Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java Check if two lists are mutually exclusive

Tags:

java

Ok, I have List a and List b

is there a way to check that no value exist between the two?

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

Between both list // 1 FAILURE

like image 269
Doc Holiday Avatar asked Mar 25 '14 20:03

Doc Holiday


2 Answers

Collections.disjoint(list1, list2)

returns true if they have no elements in common.

like image 148
Louis Wasserman Avatar answered Oct 03 '22 06:10

Louis Wasserman


Use Collections.disjoint.

Returns true if the two specified collections have no elements in common

boolean hasCommonElements = Collections.disjoint(listA, listB);
like image 34
Alexis C. Avatar answered Oct 03 '22 05:10

Alexis C.