Java Array to ArrayList arrayToArrayList(T[] array)

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

Description

Converts a Java array to an ArrayList .

License

Open Source License

Parameter

Parameter Description
array The array to convert to an ArrayList .

Return

An containing all elements of the given array.

Declaration

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

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.util.ArrayList;

public class Main {
    /**/*from   w  w w  .  j  a v  a2 s .  c  om*/
     * Converts a Java array to an {@link ArrayList}.
     * 
     * @param array The array to convert to an {@link ArrayList}.
     * 
     * @return An {@link ArrayList} containing all elements of the given array.
     */
    public static <T> ArrayList<T> arrayToArrayList(T[] array) {
        if (array == null)
            throw new IllegalArgumentException("Parameter 'array' cannot be null!");

        ArrayList<T> arrayList = new ArrayList<T>();

        for (T element : array)
            arrayList.add(element);

        return arrayList;
    }
}

Related

  1. arrayToArrayList(Object aobj[])
  2. arrayToArrayList(Object[] array)
  3. arrayToArrayList(Object[] myArray)
  4. arrayToArraylist(String[] array)
  5. arrayToArraylist(T[] array)
  6. asArrayList(Collection c)
  7. asArrayList(T... elements)
  8. asArrayList(T[] tArray)