Java Utililty Methods Collection Intersect

List of utility methods to do Collection Intersect

Description

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

Method

Setintersection(Collection> collectionOfCollections)
Returns the intersection of the Collection s of the given container Collection
Set<E> retset = new LinkedHashSet<E>();
if (!collectionOfCollections.isEmpty()) {
    final Iterator<? extends Collection<E>> collectionOfCollectionsIterator = collectionOfCollections
            .iterator();
    Collection<E> collection = collectionOfCollectionsIterator.next();
    if (collection != null) {
        retset.addAll(collection);
    while (collectionOfCollectionsIterator.hasNext()) {
        final Collection<E> collectionOther = collectionOfCollectionsIterator.next();
        if (collectionOther != null) {
            retset.retainAll(collectionOther);
return retset;
Listintersection(Collection> availableValuesByDescriptor)
intersection
List<T> result = new ArrayList<T>();
Iterator<? extends Collection<T>> iterator = availableValuesByDescriptor.iterator();
if (iterator.hasNext()) {
    Collection<T> firstSet = iterator.next();
    result.addAll(firstSet);
    while (iterator.hasNext()) {
        Collection<T> next = iterator.next();
        result.retainAll(next);
...
Listintersection(Collection... collections)
Returns a new List with only this elements which are in all of the given Collection s
final List<E> retlist = new ArrayList<E>();
if (collections.length > 0) {
    Collection<E> collection = collections[0];
    if (collection != null) {
        retlist.addAll(collection);
    for (int ii = 1; ii < collections.length && !retlist.isEmpty(); ii++) {
        Collection<E> collectionOther = collections[ii];
...
Setintersection(Collection> sets)
Determines the intersection 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());
while (iter.hasNext()) {
    result.retainAll(iter.next());
...
Listintersection(Collection a, Collection b)
intersection
List<T> list = new ArrayList<T>();
for (T element : a) {
    if (b.contains(element)) {
        list.add(element);
return list;
Collectionintersection(Collection a, Collection b)
Intersection of two collections with duplicates
return null;
Iterableintersection(Collection a, Collection b)
iterator over all elements contained in the intersection of the two collections
return () -> new Iterator<T>() {
    final Iterator<T> it = a.iterator();
    T v = null;
        while (it.hasNext()) {
            v = it.next();
            if (b.contains(v))
                break;
...
Listintersection(Collection values1, Collection values2)
intersection
Set<T> added = new HashSet<T>(), set2 = new HashSet<T>(values2);
List<T> results = new ArrayList<T>();
for (T value : values1) {
    if (set2.contains(value) && !added.contains(value)) {
        results.add(value);
        added.add(value);
return results;
Collectionintersection(final Collection a, final Collection b)
intersection
ArrayList list = new ArrayList();
Map mapa = getCardinalityMap(a);
Map mapb = getCardinalityMap(b);
Set elts = new LinkedHashSet(a);
elts.addAll(b);
Iterator it = elts.iterator();
while (it.hasNext()) {
    Object obj = it.next();
...
Collectionintersection(final Collection c1, final Collection c2)
the intersection of two collections.
final List list = new ArrayList();
final Object[] members_c1 = c1.toArray();
for (int i = 0; i < members_c1.length; i++) {
    if (c2.contains(members_c1[i])) {
        list.add(members_c1[i]);
return list;
...