Convert a varargs list/array to an List - Android java.lang

Android examples for java.lang:array convert

Description

Convert a varargs list/array to an List

Demo Code

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;

public class Main{

    /**/*from w  w  w .jav  a  2 s  .  c o m*/
     * Convert a varargs list/array to an {@link List}.  This is useful for building instances of
     * {@link List} by hand.  Note that this differs from {@link java.util.Arrays#asList} in that
     * the returned array is mutable.
     *
     * @param inputAry an array, or a varargs list
     * @return a {@link List} instance with the identical contents
     */
    public static <T> List<T> list(T... inputAry) {
        List<T> retList = new ArrayList<T>(inputAry.length);
        for (T item : inputAry) {
            retList.add(item);
        }
        return retList;
    }

}

Related Tutorials