Java List from Array asList(T[] array)

Here you can find the source of asList(T[] array)

Description

Given an input array, will return an ArrayList representation of the array.

License

Apache License

Parameter

Parameter Description
array a parameter

Return

the ArrayList corresponding to the input array. If the input is null, this also returns null. If it is empty then this will return an empty list

Declaration

public static <T> ArrayList<T> asList(T[] array) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.util.ArrayList;

public class Main {
    /**/*from  w w w.  j  a  v a 2s.c o m*/
     * Given an input array, will return an ArrayList representation of the array.
     * 
     * @param array
     * @return the ArrayList corresponding to the input array. If the input is null, this also returns null. If it is empty
     * then this will return an empty list
     */
    public static <T> ArrayList<T> asList(T[] array) {
        if (array == null) {
            return null;
        }
        ArrayList<T> list = new ArrayList<T>(array.length);
        for (T e : array) {
            list.add(e);
        }
        return list;
    }
}

Related

  1. asList(T... items)
  2. asList(T... values)
  3. asList(T... values)
  4. asList(T... values)
  5. asList(T[] a)
  6. asList(T[] array)
  7. asList(T[] array)
  8. asList(T[] array)
  9. asList(T[] array)