I have the following functionality that I’ve seen people use in order to get the differences between two lists.
Note: this is not the actual code but a representation of what I have, in actuality each number can be replaced by an object with properties.
def listA = [1,2,3,4,5]
def listB = [1,2,3,6,7]
def common = listA.intersect(listB)//expected: [1,2,3], actual: same
def all = listA.plus(listB)//expected: [1,1,2,2,3,3,4,5,6,7], actual: same
all.removeAll(common)//expected: [4,5,6,7], actual: [6,7]
Simplified,
The code
removes all matching elements. Both
1and1frombigmatch1fromsmall, so they are both removed, for the result[3]. What you probably want iswhere for each element of
smalla single matching element ofbigis removed, for the result[1, 3].See docs.