Groovy provides ‘disjoint’ method, it returns true, if
the lists are disjoint, else false.
public boolean
disjoint(Iterable right)
Returns true if the intersection of two iterables is
empty.
HelloWorld.groovy
list1 = [2, 3, 5] list2 = [5, 10, 15] list3 = [7, 14, 21] println "list1.disjoint(list2) : ${list1.disjoint(list2)}" println "list1.disjoint(list3) : ${list1.disjoint(list3)}" println "list2.disjoint(list3) : ${list2.disjoint(list3)}"
Output
list1.disjoint(list2) : false
list1.disjoint(list3) : true
list2.disjoint(list3) : true
No comments:
Post a Comment