Java Utililty Methods List Create

List of utility methods to do List Create

Description

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

Method

ListasList(Collection items)
as List
if (items == null) {
    return null;
if (items instanceof List) {
    return (List<T>) items;
return new ArrayList<T>(items);
ListasList(E... elements)
as List
if (elements == null || elements.length == 0) {
    return Collections.emptyList();
int capacity = computeListCapacity(elements.length);
ArrayList<E> list = new ArrayList<E>(capacity);
Collections.addAll(list, elements);
return list;
ListasList(E[] array)
as List
if (isEmpty(array)) {
    return new ArrayList<>();
return Arrays.asList(array);
ListasList(final int... values)
Returns a List List<Integer> representation of an primitive int array.
if (values == null)
    throw new IllegalArgumentException("the input array cannot be null");
return new AbstractList<Integer>() {
    @Override
    public Integer get(final int index) {
        return values[index];
    @Override
...
ArrayListasList(final Iterator data)
Returns data converted into list.
final ArrayList<T> list = new ArrayList<T>();
while (data.hasNext()) {
    list.add(data.next());
return list;
ArrayListasList(int[] a)
as List
ArrayList list = new ArrayList(a.length);
for (int i = 0; i < a.length; i++) {
    list.add(new Integer(a[i]));
return list;
ListasList(int[] array)
needed because Arrays.asList() won't to autoboxing, so if you give it a primitive array you get a singleton list back with just that array as an element.
List<Integer> l = new ArrayList<>();
for (int i : array) {
    l.add(i);
return l;
ListasList(Iterable iteratable)
as List
return asList(iteratable, new ArrayList<>());
CollectionasList(Object[] array)
as List
Collection result = new ArrayList(array.length);
for (int i = 0; i < array.length; i++) {
    result.add(array[i]);
return result;
ListasList(Object[] array)
Returns the list view of given array or null if array is null.
return array == null ? null : Arrays.asList(array);