Just sorting the results and comparing is an easy way if your lists are not too large:
def a = [1, 3, 2] def b = [2, 1, 3] def c = [2, 4, 3, 1] def haveSameContent(a1, a2) { a1.sort(false) == a2.sort(false) } assert haveSameContent(a, b) == true assert haveSameContent(a, c) == false
false passed to sort is designed to prevent reordering in place. If itβs normal to reorder the lists, you can remove it and possibly get a little performance.
source share