Java Utililty Methods Collection Contain

List of utility methods to do Collection Contain

Description

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

Method

booleancontainsAll(final Collection coll1, final Collection coll2)
Returns true iff all elements of coll2 are also contained in coll1 .
if (coll2.isEmpty()) {
    return true;
} else {
    final Iterator<?> it = coll1.iterator();
    final Set<Object> elementsAlreadySeen = new HashSet<Object>();
    for (final Object nextElement : coll2) {
        if (elementsAlreadySeen.contains(nextElement)) {
            continue;
...
booleancontainSameElements(Collection> sets)
contain Same Elements
if (sets.isEmpty() || sets.size() < 2)
    return false;
Iterator<Set<T>> iterator = sets.iterator();
Set<T> basicSet = iterator.next();
Set<T> actualSet;
while (iterator.hasNext()) {
    actualSet = iterator.next();
    if (actualSet.size() != basicSet.size())
...
booleancontainSameItems(Collection c1, Collection c2)
contain Same Items
Set s1 = (c1 instanceof Set) ? (Set) c1 : new HashSet(c1);
Set s2 = (c2 instanceof Set) ? (Set) c2 : new HashSet(c2);
return s1.equals(s2);
booleancontainsAny(Collection c1, Collection c2)
Returns true if there is any element that is common to both collections.
Collection smallCollection;
Collection largeCollection;
if (c1.size() < c2.size()) {
    smallCollection = c1;
    largeCollection = c2;
} else {
    smallCollection = c2;
    largeCollection = c1;
...
booleancontainsAny(Collection collection1, Collection collection2)
Queries whether two collections intersect.
Iterator it = collection2.iterator();
while (it.hasNext()) {
    if (collection1.contains(it.next())) {
        return true;
return false;
booleancontainsAny(Collection container, Collection contained)
contains Any
Collection copy = intersect(container, contained);
return !copy.isEmpty();
ObjectcontainsAny(Collection col1, Collection col2)
Tests if any value in one collection is part of another collection
Collection<?> largerCol;
Collection<?> smallerCol;
if (col1.size() > col2.size()) {
    largerCol = col1;
    smallerCol = col2;
} else {
    largerCol = col2;
    smallerCol = col1;
...
booleancontainsAny(Collection source, Collection candidates)
Return true if any element in ' candidates ' is contained in ' source '; otherwise returns false .
if (isEmpty(source) || isEmpty(candidates)) {
    return false;
for (Object candidate : candidates) {
    if (source.contains(candidate)) {
        return true;
return false;
booleancontainsAny(Collection source, Object... candidates)
Return true if any element in ' candidates ' is contained in ' source ', otherwise returns false .
if (source == null || source.isEmpty() || candidates == null || candidates.length == 0) {
    return false;
for (Object candidate : candidates) {
    if (source.contains(candidate)) {
        return true;
return false;
booleancontainsAny(Collection collection1, Collection collection2)
Checks whether any element of a collection is present in another one.
return !Collections.disjoint(collection1, collection2);