日期:2014-05-20 浏览次数:20896 次
List<Set<Integer>> l1 = new ArrayList<Set<Integer>>(); Set<Integer> s1 = new HashSet<Integer>(Arrays.asList(new Integer[]{1,2})); Set<Integer> s2 = new HashSet<Integer>(Arrays.asList(new Integer[]{3,4})); l1.add(s1); l1.add(s2); List<Set<Integer>> l2 = new ArrayList<Set<Integer>>(); Set<Integer> s3 = new HashSet<Integer>(Arrays.asList(new Integer[]{1,3})); Set<Integer> s4 = new HashSet<Integer>(Arrays.asList(new Integer[]{2,4})); l2.add(s3); l2.add(s4); for (Set<Integer> ls1 : l1) { for (Set<Integer> ls2 : l2) { Set<Integer> ts = new HashSet<Integer>(ls1); ts.retainAll(ls2); if (ts.size() > 0) { System.out.println("has same element:"); System.out.println(ts); } } }