@Test public void testIntersectListWithSelf() { assertEquals(fullList, ListUtils.intersection(fullList, fullList)); }
public static <E> List<E> intersection(final List<? extends E> list1, final List<? extends E> list2) { final List<E> result = new ArrayList<E>(); List<? extends E> smaller = list1; List<? extends E> larger = list2; if (list1.size() > list2.size()) { smaller = list2; larger = list1; } final HashSet<E> hashSet = new HashSet<E>(smaller); for (final E e : larger) { if (hashSet.contains(e)) { result.add(e); hashSet.remove(e); } } return result; }
ListUtils { public static <E> List<E> intersection(final List<? extends E> list1, final List<? extends E> list2) { final List<E> result = new ArrayList<E>(); List<? extends E> smaller = list1; List<? extends E> larger = list2; if (list1.size() > list2.size()) { smaller = list2; larger = list1; } final HashSet<E> hashSet = new HashSet<E>(smaller); for (final E e : larger) { if (hashSet.contains(e)) { result.add(e); hashSet.remove(e); } } return result; } }
ListUtils { public static <E> List<E> intersection(final List<? extends E> list1, final List<? extends E> list2) { final List<E> result = new ArrayList<E>(); List<? extends E> smaller = list1; List<? extends E> larger = list2; if (list1.size() > list2.size()) { smaller = list2; larger = list1; } final HashSet<E> hashSet = new HashSet<E>(smaller); for (final E e : larger) { if (hashSet.contains(e)) { result.add(e); hashSet.remove(e); } } return result; } private  ListUtils(); }
ListUtils { public static <E> List<E> intersection(final List<? extends E> list1, final List<? extends E> list2) { final List<E> result = new ArrayList<E>(); List<? extends E> smaller = list1; List<? extends E> larger = list2; if (list1.size() > list2.size()) { smaller = list2; larger = list1; } final HashSet<E> hashSet = new HashSet<E>(smaller); for (final E e : larger) { if (hashSet.contains(e)) { result.add(e); hashSet.remove(e); } } return result; } private  ListUtils(); static List<T> emptyIfNull(final List<T> list); static List<T> defaultIfNull(final List<T> list, final List<T> defaultList); static List<E> intersection(final List<? extends E> list1, final List<? extends E> list2); static List<E> subtract(final List<E> list1, final List<? extends E> list2); static List<E> sum(final List<? extends E> list1, final List<? extends E> list2); static List<E> union(final List<? extends E> list1, final List<? extends E> list2); static List<E> select(final Collection<? extends E> inputCollection,
            final Predicate<? super E> predicate); static List<E> selectRejected(final Collection<? extends E> inputCollection,
            final Predicate<? super E> predicate); static boolean isEqualList(final Collection<?> list1, final Collection<?> list2); static int hashCodeForList(final Collection<?> list); static List<E> retainAll(final Collection<E> collection, final Collection<?> retain); static List<E> removeAll(final Collection<E> collection, final Collection<?> remove); static List<E> synchronizedList(final List<E> list); static List<E> unmodifiableList(final List<? extends E> list); static List<E> predicatedList(final List<E> list, final Predicate<E> predicate); static List<E> transformedList(final List<E> list,
                                              final Transformer<? super E, ? extends E> transformer); static List<E> lazyList(final List<E> list, final Factory<? extends E> factory); static List<E> fixedSizeList(final List<E> list); static int indexOf(final List<E> list, final Predicate<E> predicate); static List<E> longestCommonSubsequence(final List<E> a, final List<E> b); static List<E> longestCommonSubsequence(final List<E> a, final List<E> b,
                                                       final Equator<? super E> equator); static String longestCommonSubsequence(final CharSequence a, final CharSequence b); static List<List<T>> partition(final List<T> list, final int size); }
ListUtils { public static <E> List<E> intersection(final List<? extends E> list1, final List<? extends E> list2) { final List<E> result = new ArrayList<E>(); List<? extends E> smaller = list1; List<? extends E> larger = list2; if (list1.size() > list2.size()) { smaller = list2; larger = list1; } final HashSet<E> hashSet = new HashSet<E>(smaller); for (final E e : larger) { if (hashSet.contains(e)) { result.add(e); hashSet.remove(e); } } return result; } private  ListUtils(); static List<T> emptyIfNull(final List<T> list); static List<T> defaultIfNull(final List<T> list, final List<T> defaultList); static List<E> intersection(final List<? extends E> list1, final List<? extends E> list2); static List<E> subtract(final List<E> list1, final List<? extends E> list2); static List<E> sum(final List<? extends E> list1, final List<? extends E> list2); static List<E> union(final List<? extends E> list1, final List<? extends E> list2); static List<E> select(final Collection<? extends E> inputCollection,
            final Predicate<? super E> predicate); static List<E> selectRejected(final Collection<? extends E> inputCollection,
            final Predicate<? super E> predicate); static boolean isEqualList(final Collection<?> list1, final Collection<?> list2); static int hashCodeForList(final Collection<?> list); static List<E> retainAll(final Collection<E> collection, final Collection<?> retain); static List<E> removeAll(final Collection<E> collection, final Collection<?> remove); static List<E> synchronizedList(final List<E> list); static List<E> unmodifiableList(final List<? extends E> list); static List<E> predicatedList(final List<E> list, final Predicate<E> predicate); static List<E> transformedList(final List<E> list,
                                              final Transformer<? super E, ? extends E> transformer); static List<E> lazyList(final List<E> list, final Factory<? extends E> factory); static List<E> fixedSizeList(final List<E> list); static int indexOf(final List<E> list, final Predicate<E> predicate); static List<E> longestCommonSubsequence(final List<E> a, final List<E> b); static List<E> longestCommonSubsequence(final List<E> a, final List<E> b,
                                                       final Equator<? super E> equator); static String longestCommonSubsequence(final CharSequence a, final CharSequence b); static List<List<T>> partition(final List<T> list, final int size);  }