Java List from Array convertArrayToList(T[] arrayOfObjects)

Here you can find the source of convertArrayToList(T[] arrayOfObjects)

Description

convert Array To List

License

BSD License

Parameter

Parameter Description
T type of the objects...
arrayOfObjects the array we want to convert into the List<T>

Return

an arraylist of s

Declaration

public static <T> List<T> convertArrayToList(T[] arrayOfObjects) 

Method Source Code

//package com.java2s;
/**//from ww w .  jav a2 s  .c om
 * <p>
 * This software is distributed under the <a href="http://hci.stanford.edu/research/copyright.txt">
 * BSD License</a>.
 * </p>
 * 
 * @author <a href="http://graphics.stanford.edu/~ronyeh">Ron B Yeh</a> (ronyeh(AT)cs.stanford.edu)
 */

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class Main {
    /**
     * @param <T>
     *            type of the objects...
     * @param arrayOfObjects
     *            the array we want to convert into the List<T>
     * @return an arraylist of <T>s
     */
    public static <T> List<T> convertArrayToList(T[] arrayOfObjects) {
        final ArrayList<T> list = new ArrayList<T>();
        Collections.addAll(list, arrayOfObjects);
        return list;
    }
}

Related

  1. convertArrayToList(String[] array)
  2. convertArrayToList(String[] array)
  3. convertArrayToList(String[] arrayStr)
  4. convertArrayToList(T... objects)
  5. convertArrayToList(T[] array)
  6. copyToList(T... items)
  7. copyToList(T[] array)