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 <T> Collection<T> addAll(final Collection<T> collection, final T[] items) {
    if (null != items) {
        if (null != collection) {
            Collections.addAll(collection, items);
        }//from   ww  w. j  a va  2  s  . co  m
    }
    return collection;
}

From source file:Main.java

@SafeVarargs
public static <D> ArrayList<D> createList(D... data) {
    ArrayList<D> dList = new ArrayList<>();
    Collections.addAll(dList, data);
    return dList;
}

From source file:Main.java

public static <T> HashSet<T> toHashSet(T[] items) {
    if (items == null || items.length == 0)
        return null;
    HashSet<T> set = new HashSet<>();
    Collections.addAll(set, items);
    return set;//from   w  ww  .  ja va 2s .c o m
}

From source file:Main.java

public static String[] union(String[] arr1, String[] arr2) {
    Set<String> set = new HashSet<>();
    Collections.addAll(set, arr1);
    Collections.addAll(set, arr2);
    String[] result = {};/*from   w ww  .  ja  v  a  2  s  . c o m*/
    return set.toArray(result);
}

From source file:Main.java

public static <E> List<E> newArrayList(E... elements) {
    List<E> list = new ArrayList<E>(elements.length);
    Collections.addAll(list, elements);

    return list;/*from   w w  w . j av  a 2  s  . co  m*/
}

From source file:Main.java

public static <T> ArrayList<T> toArrayList(T[] items) {
    if (items == null || items.length == 0)
        return null;
    ArrayList<T> list = new ArrayList<>();
    Collections.addAll(list, items);
    return list;/*from   w w  w  .  j  a  v a 2  s .com*/
}

From source file:Main.java

public static <E> HashSet<E> newHashSet(E... elements) {
    HashSet<E> set = new HashSet<E>(elements.length);
    Collections.addAll(set, elements);
    return set;/*from  w  w  w.  j a v a  2 s.  c o  m*/
}

From source file:Main.java

public static <T> ArrayList<T> toArrayList(T[] items) {
    if (items == null || items.length == 0) {
        return null;
    }// w w  w . ja  va2  s .c om
    ArrayList<T> list = new ArrayList<>();
    Collections.addAll(list, items);
    return list;
}

From source file:Main.java

public static <T> List<T> arrayToList(T[] t) {
    if (t == null || t.length == 0) {
        return new ArrayList<T>(0);
    }//from w  w  w.j  ava  2  s . c om
    List<T> list = new ArrayList<T>(t.length);
    Collections.addAll(list, t);
    return list;
}

From source file:Main.java

public static <E> Set<E> asSet(E... elements) {
    if (elements == null || elements.length == 0) {
        return Collections.emptySet();
    }//  ww  w .  ja v  a 2s  .  co m
    LinkedHashSet<E> set = new LinkedHashSet<E>(elements.length * 4 / 3 + 1);
    Collections.addAll(set, elements);
    return set;
}