Java Utililty Methods Collection Intersect

List of utility methods to do Collection Intersect

  1. HOME
  2. Java
  3. C
  4. Collection Intersect

Description

The list of methods to do Collection Intersect are organized into topic(s).

Method

Collection getIntersection( final Collection> 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 collection1, Collection collection2)
get Intersection
Collection<T> intersection = new ArrayList<T>(collection1);
intersection.retainAll(collection2);
return intersection;
boolean hasIntersection(Collection s1, Collection 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 c1, Collection c2)
has Intersection
boolean flag = false;
for (T t : c2) {
 if (c1.contains(t)) {
 flag = true;
 break;
return flag;
...
boolean hasIntersection(Collection col1, Collection col2)
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);


AltStyle によって変換されたページ (->オリジナル) /