Java Utililty Methods Array to List

List of utility methods to do Array to List

Description

The list of methods to do Array to List are organized into topic(s).

Method

ListfromArray(E[] array)
from Array
if ((array == null) || (array.length == 0)) {
    return new ArrayList<E>();
return new ArrayList<E>(Arrays.asList(array));
MapfromArray(final Object[][] array)
from Array
final Map<K, V> result = new HashMap<K, V>();
for (int i = 0; i < array.length; ++i) {
    final K key = (K) array[i][0];
    final V value = (V) array[i][1];
    result.put(key, value);
return result;
SetfromArray(Object array[])
Create a set containing the elements of an array
Set l = set();
for (int i = 0; i < array.length; i++) {
    l.add(array[i]);
return l;
ListfromArray(Object[] array)
from Array
if ((array == null) || (array.length == 0)) {
    return new ArrayList();
List list = new ArrayList(array.length);
for (int i = 0; i < array.length; i++) {
    list.add(array[i]);
return list;
...
ListfromArray(T array[])
Create a list containing the elements of an array
List<T> l = new ArrayList<T>(array.length);
for (T o : array) {
    l.add(o);
return l;
ListfromArray(T... array)
from Array
return array != null ? Arrays.asList(array) : null;
CollectionfromArray(T[] array, Class clazz)
from Array
try {
    Collection<T> collection = clazz.newInstance();
    for (T o : array) {
        collection.add(o);
    return collection;
} catch (Exception e) {
    return null;
...
ArrayListfromArray(T[] objects)
from Array
ArrayList<T> arrayList = new ArrayList<T>();
Collections.addAll(arrayList, objects);
return arrayList;
ListnewList(final T... elements)

Returns a List with a initial capacity which equals to the number of elements given in parameter and with those elements already added.

final List<T> retval = new ArrayList<T>(elements.length);
Collections.addAll(retval, elements);
return retval;
ListnewList(final T... elements)
new List
final ArrayList<T> list = new ArrayList<>();
for (final T element : elements) {
    list.add(element);
return list;