List of usage examples for java.util List addAll
boolean addAll(Collection<? extends E> c);
From source file:Main.java
public static <T> List<T> varargToList(final T first, final T[] others) { final List<T> list = new ArrayList<>(others.length + 1); list.add(first);/*from ww w .j ava 2s . co m*/ list.addAll(Arrays.asList(others)); return list; }
From source file:Main.java
/** * Return a new list with element prepended to previous list. *//*from w ww .ja va2s . com*/ public static <A> List<A> prependToList(A elem, List<A> list) { List<A> answer = new ArrayList<A>(list.size() + 1); answer.add(elem); answer.addAll(list); return answer; }
From source file:Main.java
public static <I> List<I> flatten(final List<List<I>> in) { final List<I> retVal = new ArrayList<I>(); for (final List<I> list : in) { retVal.addAll(list); }//from w w w .j a va 2 s .c o m return retVal; }
From source file:co.kademi.kdom.MultiJexlContext.java
public static MultiJexlContext build(JexlContext... contexts) { List<JexlContext> list = new ArrayList<>(); list.addAll(Arrays.asList(contexts)); return new MultiJexlContext(list); }
From source file:Main.java
public static List<Object> combineArrays(Object[]... objects) { List<Object> list = new ArrayList<Object>(); for (int i = 0; i < objects.length; i++) { list.addAll(Arrays.asList(objects[i])); }/*from ww w .ja va 2 s. c o m*/ return list; }
From source file:Main.java
public static List<String> removeDuplicate(List<String> list) { HashSet<String> hashSet = new HashSet<String>(list); list.clear();//from www. j a v a 2 s .c om list.addAll(hashSet); return list; }
From source file:Main.java
@SuppressWarnings({ "rawtypes", "unchecked" }) public static String[] joinStringArray(String[]... arrays) { int size = 0; for (String[] array : arrays) { size += array.length;//from w w w .j a va 2s . c o m } java.util.List list = new java.util.ArrayList(size); for (String[] array : arrays) { list.addAll(java.util.Arrays.asList(array)); } return (String[]) list.toArray(new String[size]); }
From source file:Main.java
public static <T> List<T> flatten(List<? extends Collection<T>> list) { List<T> flat = new ArrayList<>(); for (Collection<T> collection : list) { flat.addAll(collection); }//w w w.j av a2s .com return flat; }
From source file:Main.java
public static <T> List<T> union(List<List<T>> collections) { if (collections.size() <= 0) { return new LinkedList<>(); } else if (collections.size() == 1) { return collections.get(0); } else {//from w w w.jav a 2 s. c o m List<T> result = new LinkedList<>(); for (List<T> list : collections) { result.addAll(list); } return result; } }
From source file:Main.java
/** * Merges the given two lists in a new list, but without duplicates. *///from w ww . j a v a 2 s . com public static <T> List<T> mergeNoDuplicates(List<T> sourceList1, List<T> sourceList2) { List<T> ret = alist(sourceList1.size() + sourceList2.size()); ret.addAll(sourceList1); for (T e : sourceList2) { if (false == ret.contains(e)) ret.add(e); } return ret; }