Java List from Array asList(T... a)

Here you can find the source of asList(T... a)

Description

Return an ArrayList with the passed array or elements as the initial contents.

License

Open Source License

Parameter

Parameter Description
T type of list elements
a An array or sequence of params of type T

Declaration

public static <T> ArrayList<T> asList(T... a) 

Method Source Code

//package com.java2s;
/*/*from   w  ww . j  a  va 2  s.  c o m*/
 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
 * All rights reserved.
 * This component and the accompanying materials are made available
 * under the terms of the License "Eclipse Public License v1.0"
 * which accompanies this distribution, and is available
 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
 *
 * Initial Contributors:
 * Nokia Corporation - initial contribution.
 *
 * Contributors:
 *
 * Description: 
 *
 */

import java.util.ArrayList;

public class Main {
    /**
     * Return an ArrayList with the passed array or elements
     * as the initial contents. Differs from Arrays#asList() in that
     * the list is not fixed sized.
     * @param <T> type of list elements
     * @param a An array or sequence of params of type T
     */
    public static <T> ArrayList<T> asList(T... a) {
        ArrayList<T> result = new ArrayList<T>();
        for (T t : a) {
            result.add(t);
        }
        return result;
    }
}

Related

  1. asList(String valuesSeparatedBy, String delimiter)
  2. asList(String... args)
  3. asList(String... strings)
  4. asList(T element)
  5. asList(T firstItem, T... otherItems)
  6. asList(T... a)
  7. asList(T... a)
  8. asList(T... a)
  9. asList(T... args)