CollectionUtils { public static <E> Object getDuplicate(Collection<E> coll, E o, String field, Class fieldClass) { return getDuplicate(coll, o, field, fieldClass, null); } 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 public void getDuplicate() { A _a = new A(1, "2", 3); A _b = new A(1, "a", 5); A _c = new A(4, "!", 3); A _d = new A(4, "2", 5); LinkedList<A> aList = new LinkedList<>(); aList.add(_a); aList.add(_b); aList.add(_c); assertEquals(_a, CollectionUtils.getDuplicate(aList, _d, "b", String.class)); assertEquals(2, aList.size()); assertEquals(_c, CollectionUtils.getDuplicate(aList, _d, "a", Integer.class)); assertEquals(1, aList.size()); assertEquals(_b, CollectionUtils.getDuplicate(aList, _d, "c", Object.class)); assertEquals(0, aList.size()); assertNull(CollectionUtils.getDuplicate(aList, _d, "d", Object.class)); assertEquals(0, aList.size()); aList.add(_a); aList.add(_b); aList.add(_c); assertNull(CollectionUtils.getDuplicate(aList, _d, "d", Object.class)); assertEquals(3, aList.size()); }