public static void main(String[] args) { List<Integer> list1 = new ArrayList<>(); list1.add(1); list1.add(2); List<Integer> list2 = new ArrayList<>(); list2.add(2); list2.add(3); List<Integer> list3 = new ArrayList<>(); list3.add(4); boolean disjoint1 = Collections.disjoint(list1, list2); boolean disjoint2 = Collections.disjoint(list1, list3); System.out.println(disjoint1); System.out.println(disjoint2); }
当两个集合中没有相同的元素的时候返回true
当有相同的元素的时候返回false