How can I compare two lists in Groovy

后端 未结 4 1591
北海茫月
北海茫月 2020-12-15 04:33

How can I compare the items in two lists and create a new list with the difference in Groovy?

4条回答
  •  半阙折子戏
    2020-12-15 05:33

    I'd just use the arithmetic operators, I think it's much more obvious what's going on:

    def a = ["foo", "bar", "baz", "baz"]
    def b = ["foo", "qux"]
    
    assert ["bar", "baz", "baz", "qux"] == ((a - b) + (b - a))
    

提交回复
热议问题