两个list查看是否有交集
String s1 = "50000,100000,200000,300000,500000,"; String s2 = "10000,30000,50000,100000,"; String[] a1 = s1.split(","); String[] a2 = s2.split(","); List<String> list = new ArrayList(Arrays.asList(a1)); list.retainAll(Arrays.asList(a2)); // list 中的就是交集了 for(String s : list){ System.out.println(s); }
如果仅仅需要知道是否有交集
Collections.disjoint(list1,list2)
false: 有交集
true: 没有交集