List of usage examples for java.util Collection contains
boolean contains(Object o);
From source file:Main.java
public static boolean nonEmptyIntersection(Collection<? extends Object> collection1, Collection<? extends Object> collection2) { for (Object obj : collection1) { if (collection2.contains(obj)) { return true; }/* w ww . ja va 2 s . com*/ } return false; }
From source file:Main.java
public static <T> ArrayList<T> inter(Collection<T> l1, Collection<T> l2) { ArrayList<T> l = new ArrayList<>(); for (T e : l1) { if (l2.contains(e)) { l.add(e);/*from w ww . j a v a 2s . com*/ } } return l; }
From source file:Main.java
public static boolean intersect(Collection<?> a, Iterable<?> iterable) { for (Object ele : iterable) { if (a.contains(ele)) return true; }//from w w w . j a v a 2 s . co m return false; }
From source file:Main.java
/** * Checks if any of the elements in the first collection can be found in the * second collection.//www. ja v a2s . c o m * * @param findAnyOfThese which elements to look for. * @param inThisCollection where to look for them. * @param <E> type of the elements in question. * @return {@code true} if any of the elements in {@code findAnyOfThese} can * be found in {@code inThisCollection}, {@code false} otherwise. */ public static <E> boolean isAnyIncludedIn(Collection<E> findAnyOfThese, Collection<E> inThisCollection) { for (E findThisItem : findAnyOfThese) { if (inThisCollection.contains(findThisItem)) { return true; } } return false; }
From source file:Main.java
public static <T> List<T> intersection(Collection<T> a, Collection<T> b) { List<T> list = new ArrayList<>(); for (T element : a) { if (b.contains(element)) { list.add(element);//from ww w .j ava 2 s . c o m } } return list; }
From source file:Main.java
/** @return whether given coll contains all elements of other, using a naive/basic algorithm. */ public static boolean containsAll(Collection<?> coll, Collection<?> other) { for (Object otherElement : other) { if (!coll.contains(otherElement)) return false; }/* w ww.java 2 s . c o m*/ return true; }
From source file:Main.java
/** * Check whether <code>c2</code> contains any element in <code>c1</code>. * @param <E> The type of the arguments. * @param c1 Base collection against which we check. * @param c2 Collection which should contain any of the elements in c1. * @return <code>true</code> iff at least one element of <code>c1</code> is * contained in <code>c2</code>. *//*from w w w . j a v a 2 s.co m*/ public static <E> boolean containsAny(Collection<E> c1, Collection<E> c2) { for (final E elem : c1) { if (c2.contains(elem)) { return true; } } return false; }
From source file:Main.java
/** * Check whether <code>c2</code> contains any element in <code>c1</code>. * @param <E> The type of the arguments. * @param c1 Base collection against which we check. * @param c2 Collection which should contain any of the elements in c1. * @return <code>true</code> iff at least one element of <code>c1</code> is * contained in <code>c2</code>. *///from w ww. j a va 2 s . com public static <E> boolean containsAny(E[] c1, Collection<E> c2) { for (final E elem : c1) { if (c2.contains(elem)) { return true; } } return false; }
From source file:Main.java
public static <T> int intersectionSize(Collection<T> one, Collection<T> two) { int intersection = 0; for (T item : one) { if (two.contains(item)) { intersection++;//from w w w.jav a 2s.c o m } } return intersection; }
From source file:Main.java
public static boolean containsAny(Collection<?> source, Collection<?> candidates) { for (Object o : candidates) { if (source.contains(o)) { return true; }/* w w w . ja v a 2 s . c o m*/ } return false; }