CollectionUtils { public static Object[] intersection(Object[] a, Object[] b) { if (a == null || b == null || a.length == 0 || b.length == 0) return null; LinkedHashSet<Object> set = new LinkedHashSet<>(), result = new LinkedHashSet<>(); Collections.addAll(set, a); for (Object bi : b) if (set.contains(bi)) result.add(bi); return result.toArray(); } private  CollectionUtils(); static List<String> removeAllByStrWithSeparator(List<String> originList,
                                                           String strWithSeparator, String separator); static Object[] intersection(Object[] a, Object[] b); static Collection<T> intersection(Collection<T> a, Collection<T> b); static Object getDuplicate(Collection<E> coll, E o, String field, Class fieldClass); static Object getDuplicate(Collection<E> coll, E o, String fieldName,
                                          Class fieldClass, Class elementClass); static Collection<T> remove(Collection<T> coll, final String field, final Object... removes); static int getNthNumberMin(int[] arr, int n); static int getNthNumberMax(int[] arr, int n); static Map<Y, Map<X, Z>> exchangeKeys(Map<X, Map<Y, Z>> map); static String join(T[] arr, String separator); static String join(Collection<T> list, String separator);  }
@Test @SuppressWarnings("all") public void duplicate() throws Exception { { Integer[] a = new Integer[]{1, 2, 3}; Integer[] b = new Integer[]{3}; Integer[] c = new Integer[]{4}; Integer[] d = null; assertEquals(3, intersection(a, b)[0]); assertEquals(0, intersection(b, c).length); assertEquals(true, intersection(c, d) == null); } { List<String> a = new LinkedList<>(); a.add("a"); a.add("c"); a.add("d"); List<String> b = new LinkedList<>(); b.add("a"); b.add("b"); b.add("c"); Collection<String> result = intersection(a, b); Iterator iterator = result.iterator(); assertEquals(2, result.size()); assertEquals("a", iterator.next()); assertEquals("c", iterator.next()); assertEquals(3, a.size()); assertEquals(3, b.size()); } }