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

Collectionintersection(final Collection a, final Collection b)
intersection
if (a == null || a.size() == 0 || b == null || b.size() == 0) {
    return null;
List<T> result = new ArrayList<T>();
Map<T, Integer> mapa = getCardinalityMap(a);
Map<T, Integer> mapb = getCardinalityMap(b);
Set<T> elts = new HashSet<T>(a);
elts.addAll(b);
...
Listintersection(final Collection c1, final Collection c2)
return a such that a exists in c1 and a exists in c2.
if (c1 == null || c2 == null) {
    return new ArrayList<>();
if (c1.size() == 0 || c2.size() == 0) {
    return new ArrayList<>();
final List<T> intersection = new ArrayList<>();
for (final T current : c1) {
...
intintersectionSize(Collection c1, Collection c2)
Calculate the size of intersection between two collections.
int size = 0;
if (c1.size() < c2.size()) {
    for (Object o : c1) {
        if (c2.contains(o)) {
            size++;
} else {
...
booleanintersects(Collection c1, Collection c2)
Checks if two collections have any elemnts in common
for (Iterator i = c1.iterator(); i.hasNext();) {
    if (c2.contains(i.next()))
        return true;
return false;
booleanintersects(Collection c0, Collection c1)
Returns whether two collections have any elements in common.
for (E e : c1) {
    if (c0.contains(e)) {
        return true;
return false;
booleanintersectsWith(Collection S1, Collection S2)
check whether set S1 intersects with the set S2
for (Object o : S1) {
    if (S2.contains(o)) {
        return true;
return false;
ArrayListmakeIntersection(Collection a, Collection b)
make Intersection
ArrayList<K> intersection = new ArrayList<K>();
if (a != null && b != null && b.size() > 0) {
    K o = null;
    for (Iterator<? extends K> iter = a.iterator(); iter.hasNext();) {
        o = iter.next();
        if (b.contains(o))
            intersection.add(o);
return intersection;
intsizeOfIntersection(Collection a, Collection b)
size Of Intersection
int count = 0;
for (Object o : a)
    if (b.contains(o))
        count++;
return count;