Java List from Array array2ArrayList(final T[] array)

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

Description

Converts an array to the appropriate ArrayList

License

MIT License

Parameter

Parameter Description
T The type held in the array
array The array of values

Return

An ArrayList of the same values

Declaration

public static <T> ArrayList<T> array2ArrayList(final T[] array) 

Method Source Code

//package com.java2s;
/*/*w ww  . ja va2  s  .c o m*/
 * oxCore is available under the MIT License (2008). See http://opensource.org/licenses/MIT for full text.
 *
 * Copyright (c) 2014, Gluu
 */

import java.util.ArrayList;
import java.util.Arrays;

import java.util.List;

public class Main {
    /**
     * Converts an array to the appropriate ArrayList
     * 
     * @param <T>
     *            The type held in the array
     * @param array
     *            The array of values
     * @return An ArrayList<T> of the same values *
     */
    public static <T> ArrayList<T> array2ArrayList(final T[] array) {
        if ((array == null) || (array.length == 0)) {
            return new ArrayList<T>();
        }
        final List<T> list = Arrays.asList(array);
        return new ArrayList<T>(list);
    }
}

Related

  1. array2List(Object[] obj)
  2. array2list(String[] array)
  3. array2List(T... array)
  4. arrayAsArrayList(E... elements)