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

booleancontainsOne(final Collection sup, final Collection parts)
Return true , if sup contains at least one item from parts .
for (E part : parts) {
    if (sup.contains(part))
        return true;
return false;
booleancontainsPrefix(final Collection words, final String prefix)
It returns whether at least a word contains the prefix.
return words.stream().anyMatch(word -> word.startsWith(prefix));
booleancontainsPrefix(String str, Collection prefixes)
if str starts with a prefix which is included in prefixes collection return true, otherwise return false.
if (str != null && prefixes != null) {
    Iterator it = prefixes.iterator();
    while (it.hasNext()) {
        String prefix = (String) it.next();
        if (str.startsWith(prefix)) {
            return true;
return false;
booleancontainsSafe(Collection collection, V value)
Type-safe wrapper for Collection#contains(Object) method.
return collection.contains(value);
booleancontainsSame(Collection first, Collection second)

Checks if the given two Collection s contains the same elements in any order.

if (first != null) {
    if (second != null) {
        if (first.size() == second.size()) {
            Collection<T> firstCopy = new LinkedList<T>(first);
            boolean same = true;
            Iterator<T> secondIter = second.iterator();
            while (same && secondIter.hasNext()) {
                T secondNext = secondIter.next();
...
booleancontainsSameItems(Collection col1, Collection col2)
contains Same Items
if (col1 == col2)
    return true;
if (col1 == null || col2 == null)
    return false;
if (col1.size() != col2.size())
    return false;
List<Object> checkList = new ArrayList<Object>(col1);
checkList.removeAll(col2);
...
booleancontainsSameType(Object o, Collection collection)
contains Same Type
boolean result = false;
for (Iterator iterator = collection.iterator(); iterator.hasNext();) {
    Object o1 = iterator.next();
    if (o1.getClass() == o.getClass()) {
        result = true;
        break;
return result;
booleancontainsSome(Collection source, Collection target)
Returns true if source contains at least one element in target.
if (source == target)
    return true;
if ((source == null) != (target == null))
    return false;
return !Collections.disjoint(source, target);
booleancontainsSome(final Collection c1, final Collection c2)
contains Some
for (E e : c2)
    if (c1.contains(e))
        return true;
return false;
booleancontainsSome(HashSet s1, Collection other)
contains Some
for (T t : other)
    if (s1.contains(t))
        return true;
return false;