Java Check if two lists are mutually exclusive

Ok i have list a and list b

Is there any way to check if there is between two?

List a // 1,2,4,5
List B // 1,6,7,8

Between both lists // 1 FAILURE

+4
source share
4 answers
Collections.disjoint(list1, list2)

returns trueif they do not have common elements.

+9
source

Use Collections.disjoint.

Returns true if the two specified collections do not have elements in common

boolean hasCommonElements = Collections.disjoint(listA, listB);
+4
source

Collections.disjoint():

public static boolean disjoint (Collection c1, Collection c2): true, .

:

List<Integer> a = new ArrayList<Integer>();
List<Integer> b = new ArrayList<Integer>();

System.out.println(Collections.disjoint(a, b));
+2

Collections.disjoint(a, b); : true, .

+2

Source: https://habr.com/ru/post/1533412/


All Articles