Java tutorial
//package com.java2s; import java.util.*; public class Main { /** * added by liyong */ public static <T> Collection<T> same(Collection<T> c1, Collection<T> c2) { if (isEmpty(c1) || isEmpty(c2)) return new ArrayList<T>(0); List<T> result = new ArrayList<T>(); for (T item : c2) { if (c1.contains(item)) { result.add(item); } } return result; } /** * added by liyong */ public static boolean isEmpty(Collection c) { return c == null || c.isEmpty(); } /** * added by liyong */ public static boolean isEmpty(Map map) { return map == null || map.isEmpty(); } }