List of usage examples for java.util ArrayList addAll
public boolean addAll(Collection<? extends E> c)
From source file:Main.java
public static <T> List<T> union(List<T> list1, List<T> list2) { ArrayList<T> result = new ArrayList<>(list1); result.addAll(list2); return result; }
From source file:Main.java
/** * create list from array// w w w. j a v a2s .c o m * * @param <T> * @param values * @return array values in list */ public static <T> ArrayList<T> fromArray(T... values) { ArrayList<T> list = new ArrayList<T>(); list.addAll(Arrays.asList(values)); return list; }
From source file:Main.java
public static int countCommElmts(ArrayList<String> u, ArrayList<String> v) { ArrayList<String> listOne = new ArrayList<String>(); listOne.addAll(u); listOne.retainAll(v);/*from w w w. j a v a 2 s. c om*/ return listOne.size(); }
From source file:Main.java
public static <T> ArrayList<T> newArrayList(T... elements) { List<T> tmp = Arrays.asList(elements); if (tmp instanceof ArrayList) { return (ArrayList<T>) tmp; }// w w w .ja v a2s . c om ArrayList<T> result = new ArrayList<T>(); result.addAll(tmp); return result; }
From source file:Main.java
public static <T> ArrayList<T> toArrayList(Object[] arr) { List list = toList(arr);//w w w .j ava2 s . c o m ArrayList<T> arrayList = new ArrayList<T>(); arrayList.addAll(list); return arrayList; }
From source file:Main.java
/** * Concatenate two String arrays.// w ww . j av a 2 s . c o m * @param array1 cannot be null. * @param array2 cannot be null. * @return result. */ public static String[] concat(String[] array1, String[] array2) { ArrayList<String> result = new ArrayList<>(); result.addAll(Arrays.asList(array1)); result.addAll(Arrays.asList(array2)); String[] array = new String[result.size()]; result.toArray(array); return array; }
From source file:Main.java
public static <T> List<T> readOnlyCopy(List<T> orig) { if (orig.isEmpty()) return Collections.emptyList(); if (orig.size() == 1) return Collections.singletonList(orig.get(0)); ArrayList<T> copy = new ArrayList<>(orig.size()); copy.addAll(orig); return Collections.unmodifiableList(copy); }
From source file:Main.java
public static <T> List<T> concat(Collection<? extends T> xs, Collection<? extends T> ys) { ArrayList<T> result = new ArrayList<>(xs.size() + ys.size()); result.addAll(xs); result.addAll(ys);/*from w w w .ja v a 2s .co m*/ return result; }
From source file:Main.java
public static <T> ArrayList<T> toArrayList(Collection<T> col) { ArrayList<T> list = new ArrayList<T>(); if (col != null) { list.addAll(col); }/*ww w . j a v a 2 s . c o m*/ return list; }
From source file:Main.java
/** * Return the first N items in a collection. * *///w w w. j a v a2s .c o m public static <T> List<T> head(Collection<T> input, int count) { List<T> result = Lists.newArrayList(); ArrayList<T> tmp = Lists.newArrayList(); tmp.addAll(input); for (int i = 0; i < input.size(); i++) { if (result.size() == count) break; result.add(tmp.get(i)); } return result; }