List of utility methods to do Collection Union
List | union(Collection c1, Collection c2) union List collection = new ArrayList(); collection.addAll(c1); collection.addAll(c2); return collection; |
Set | union(Collection coll) Returns the union of all the sets given in a collection. Set set = new HashSet(); for (Iterator i = coll.iterator(); i.hasNext();) { set.addAll((Collection) i.next()); return set; |
Collection | union(Collection extends T> collection1, Collection extends T> collection2) Given two collections of elements of type if (isEmpty(collection1)) { if (isEmpty(collection2)) { return Collections.emptyList(); return new ArrayList<T>(collection2); if (isEmpty(collection2)) { return new ArrayList<T>(collection1); ... |
List | union(Collection Adds all elements of two collections to a new LinkedList. List<E> result = new LinkedList<E>(); result.addAll(c1); result.addAll(c2); return result; |
Set | union(Collection Determines the union of a collection of sets. Set<T> result = new HashSet<>(); if (sets.isEmpty()) { return result; Iterator<Set<T>> iter = sets.iterator(); result.addAll(iter.next()); if (sets.size() == 1) { return result; ... |
Collection | union(Collection Union of two collections with duplicates return null;
|
List | union(Collection intersection of c1 and c2, does not change input collections, returns new collection (list) if (c1 == null && c2 == null) { return Collections.emptyList(); if (c1 == null) { return new ArrayList<>(c2); if (c2 == null) { return new ArrayList<>(c1); ... |
List | union(Collection returns a List of union objects, i.e. ArrayList<T> union = new ArrayList<T>(); for (T obj : initial) { if (other.contains(obj)) union.add(obj); return union; |
Set | union(Collection union HashSet<T> results = new HashSet<>(lhs.size() + rhs.size()); results.addAll(lhs); results.addAll(rhs); return results; |
Collection | union(Collection union Collection<T> union = new ArrayList<>(); for (T t : set1) { union.add(t); for (T t : set2) { union.add(t); return union; ... |