List of usage examples for java.util Collection add
boolean add(E e);
From source file:Main.java
public static <E> Collection<E> List2Collection(List<E> elements) { if (elements == null || elements.size() <= 0) { return null; }// w w w .j a v a 2 s .c o m Collection<E> collections = elements; for (E e : elements) { collections.add(e); } return collections; }
From source file:Main.java
public static <K, V> Map<K, Collection<V>> toMap(final Collection<? extends V> items, final Function<V, K> mapper) { Map<K, Collection<V>> buffer = new HashMap<K, Collection<V>>(); // TODO this isn't probably thread-safe items.stream().forEach(item -> {/* w ww. ja va 2 s . c o m*/ K key = mapper.apply(item); Collection<V> c = buffer.getOrDefault(key, new ArrayList<V>()); c.add(item); buffer.put(key, c); }); return buffer; }
From source file:Main.java
/** * Copy Iterable content to a list. /*from w ww . ja v a 2s . c o m*/ * @param iter : Iterable * @return */ public static <E> Collection<E> makeCollection(Iterable<E> iter) { Collection<E> list = new LinkedList<E>(); for (E item : iter) { list.add(item); } return list; }
From source file:Main.java
/** * Adds a value to the collection if the boolean expression is true. * Returns the collection as a convenience for chained invocations. * * @since 1.0.8//w ww.j ava 2 s.c o m */ public static <T> Collection<T> addIf(Collection<T> coll, T value, boolean expr) { if (expr) coll.add(value); return coll; }
From source file:Main.java
public static <T> void addAll(Collection<T> target, Iterable<? extends T> source) { for (T e : source) target.add(e); }
From source file:Main.java
public static void arrayToCollection(Collection c, Object[] array) { for (int i = 0; i < array.length; i++) c.add(array[i]); }
From source file:Main.java
/** * @param element/*from w ww. j a v a 2s . c o m*/ * @param collection */ public static <O> void addIfNotNull(final O element, final Collection<O> collection) { if (element != null) { collection.add(element); } }
From source file:Main.java
public static void addAll(final Collection<Integer> coll, final int... values) { for (final int i : values) coll.add(i); }
From source file:Main.java
public static <T> void addAll(Collection<T> collection, T... array) { for (T t : array) { collection.add(t); }/*from w w w. ja va 2 s.co m*/ }
From source file:Main.java
public static <T> void addAll(Collection<T> collection, T[] array) { for (int i = 0; i < array.length; ++i) collection.add(array[i]); }