< prev index next >

src/java.base/share/classes/java/util/Arrays.java

Print this page




4322      *
4323      * @param <T> the class of the objects in the array
4324      * @param a the array by which the list will be backed
4325      * @return a list view of the specified array
4326      * @throws NullPointerException if the specified array is {@code null}
4327      */
4328     @SafeVarargs
4329     @SuppressWarnings("varargs")
4330     public static <T> List<T> asList(T... a) {
4331         return new ArrayList<>(a);
4332     }
4333 
4334     /**
4335      * @serial include
4336      */
4337     private static class ArrayList<E> extends AbstractList<E>
4338         implements RandomAccess, java.io.Serializable
4339     {
4340         @java.io.Serial
4341         private static final long serialVersionUID = -2764017481108945198L;

4342         private final E[] a;
4343 
4344         ArrayList(E[] array) {
4345             a = Objects.requireNonNull(array);
4346         }
4347 
4348         @Override
4349         public int size() {
4350             return a.length;
4351         }
4352 
4353         @Override
4354         public Object[] toArray() {
4355             return Arrays.copyOf(a, a.length, Object[].class);
4356         }
4357 
4358         @Override
4359         @SuppressWarnings("unchecked")
4360         public <T> T[] toArray(T[] a) {
4361             int size = size();




4322      *
4323      * @param <T> the class of the objects in the array
4324      * @param a the array by which the list will be backed
4325      * @return a list view of the specified array
4326      * @throws NullPointerException if the specified array is {@code null}
4327      */
4328     @SafeVarargs
4329     @SuppressWarnings("varargs")
4330     public static <T> List<T> asList(T... a) {
4331         return new ArrayList<>(a);
4332     }
4333 
4334     /**
4335      * @serial include
4336      */
4337     private static class ArrayList<E> extends AbstractList<E>
4338         implements RandomAccess, java.io.Serializable
4339     {
4340         @java.io.Serial
4341         private static final long serialVersionUID = -2764017481108945198L;
4342         @SuppressWarnings("serial") // Not statically typed as Serializable
4343         private final E[] a;
4344 
4345         ArrayList(E[] array) {
4346             a = Objects.requireNonNull(array);
4347         }
4348 
4349         @Override
4350         public int size() {
4351             return a.length;
4352         }
4353 
4354         @Override
4355         public Object[] toArray() {
4356             return Arrays.copyOf(a, a.length, Object[].class);
4357         }
4358 
4359         @Override
4360         @SuppressWarnings("unchecked")
4361         public <T> T[] toArray(T[] a) {
4362             int size = size();


< prev index next >