java 求交集
Collection<String> A=new ArrayList<String>(); Collection<String> B=new ArrayList<String>(); A.add("A"); A.add("B"); A.add("C"); B.add("D"); B.add("B"); B.add("C"); System.out.println(A); System.out.println(B); boolean res=A.retainAll(B); System.out.println(res); System.out.println(A); System.out.println(B);
运行结果: [A, B, C] [D, B, C] true [B, C] [D, B, C]