List of utility methods to do Collection Intersect
Collection> | getIntersection( final Collection extends Collection extends Object>> collections) get Intersection final List<Collection<?>> collectionsList = new ArrayList<Collection<?>>(collections); final Collection<Object> intersection = new HashSet<>(); if (collectionsList.size() != 0) { intersection.addAll(collectionsList.get(0)); for (int i = 1; i < collections.size() && intersection.size() > 0; i++) { intersection.retainAll(new HashSet<>(collectionsList.get(i))); return intersection; |
Collection | getIntersection(Collection get Intersection Collection<T> intersection = new ArrayList<T>(collection1); intersection.retainAll(collection2); return intersection; |
boolean | hasIntersection(Collection extends T> s1, Collection extends T> s2) has Intersection if (s1 == null || s2 == null) return false; int n1 = s1.size(); int n2 = s2.size(); if (n2 < n1) { Collection<? extends T> t = s1; s1 = s2; s2 = t; ... |
boolean | hasIntersection(Collection> a, Collection> b) Returns true if Collections have intersection. return !isDisjoint(a, b);
|
boolean | hasIntersection(Collection has Intersection boolean flag = false; for (T t : c2) { if (c1.contains(t)) { flag = true; break; return flag; ... |
boolean | hasIntersection(Collection has Intersection if (col2.size() < col1.size()) { Collection<T> tmp = col1; col1 = col2; col2 = tmp; for (T item : col1) { if (col2.contains(item)) return true; ... |
boolean | hasIntersection(final Collection a, final Collection b) Returns true iff the given Collection s. if (a.size() < 50 && b.size() < 50) { Iterator it = a.iterator(); while (it.hasNext()) if (b.contains(it.next())) return true; } else if (a.size() < b.size()) { HashSet bSet = new HashSet(b); Iterator it = a.iterator(); ... |
List | intersect(Collection c1, Collection c2) intersect List c1_ = new ArrayList(); List c1__ = new ArrayList(); if (isNotEmpty(c1)) { c1_.addAll(c1); c1__.addAll(c1); c1__.removeAll(c2); c1_.removeAll(c1__); return c1_; |
Collection | intersect(Collection c1, Collection c2) Computes the intersection between two collections return intersect(c1, c2, null);
|
boolean | intersect(Collection> collection, Collection> otherCollection) intersect return !Collections.disjoint(collection, otherCollection);
|