Example usage for java.util Collections addAll

List of usage examples for java.util Collections addAll

Introduction

In this page you can find the example usage for java.util Collections addAll.

Prototype

@SafeVarargs
public static <T> boolean addAll(Collection<? super T> c, T... elements) 

Source Link

Document

Adds all of the specified elements to the specified collection.

Usage

From source file:Main.java

public static <E> ArrayList<E> newArrayList(E... elements) {
    ArrayList<E> list = new ArrayList<E>(elements.length);
    Collections.addAll(list, elements);
    return list;//w  ww.j a v  a  2  s. co  m
}

From source file:Main.java

public static <T> ArrayList<T> asArrayList(T[] array) {
    ArrayList<T> arrayList = new ArrayList<T>();
    if (array == null) {
        return arrayList;
    }/* www .  j a  v  a  2  s.  c  om*/
    Collections.addAll(arrayList, array);
    return arrayList;
}

From source file:Main.java

public static <T> List<T> asList(T... array) {
    if (array == null)
        return new ArrayList<T>();

    List<T> result = new ArrayList<T>();
    Collections.addAll(result, array);

    return result;
}

From source file:Main.java

public static Set<String> asSet(String[] names) {
    Set<String> set = createHashSet(names.length);
    Collections.addAll(set, names);
    return set;//from www.java  2  s .  co  m
}

From source file:Main.java

public static <T> List<T> asModifiableList(final T[] array) {
    if (!isEmpty(array)) {
        final List<T> result = new ArrayList<>(array.length);

        Collections.addAll(result, array);

        return result;
    } else {//w  w w  .jav  a  2 s.  co  m
        return new ArrayList<T>();
    }
}

From source file:Main.java

@SuppressWarnings("unchecked")
public static <T> ArrayList<T> asArrayList(T... array) {
    ArrayList<T> result = new ArrayList<T>();
    if (array != null) {
        Collections.addAll(result, array);
    }//from w  ww .  j  a  va  2s  .  c o m
    return result;
}

From source file:Main.java

public static <T> Set<T> asSet(T... ts) {
    HashSet<T> set = new HashSet<T>(ts.length);
    Collections.addAll(set, ts);
    return set;/*from  w ww .  j a  v  a 2s  .  c  om*/
}

From source file:Main.java

/**
 * Turns a list of vararg parameters into a set.
 *
 * @param  ts  The vararg parameters.// w  w  w .  java 2  s .  c  om
 * @param  <T> The type of the parameters.
 *
 * @return A set created by adding the parameters in the order presented into a set.
 */
public static <T> Set<T> paramsToSet(T... ts) {
    Set<T> result = new HashSet<>();

    Collections.addAll(result, ts);

    return result;
}

From source file:Main.java

/**
 * Creates a list of values//from w  w w  .  jav  a2 s. c o m
 *
 * @param items Items to store in the list
 * @param <T>   Type of value stored in the list
 * @return A list of values
 */
@SafeVarargs
public static <T> List<T> listOf(T... items) {
    List<T> results = new ArrayList<>(items.length);
    Collections.addAll(results, items);

    return results;
}

From source file:Main.java

/**
 * A version of {@link Collection#addAll(Collection)} that works on varargs without calling Arrays.asList, which is
 * a performance and memory boost//  w w w . j  av a 2 s.co m
 */
public static <T> void addAll(Collection<T> collection, T... objects) {
    if (objects != null) {
        Collections.addAll(collection, objects);
    }
}