Groovy not in collection

前端 未结 8 1257
Happy的楠姐
Happy的楠姐 2021-02-04 23:50

The groovy way to see if something is in a list is to use \"in\"

   if(\'b\' in [\'a\',\'b\',\'c\'])

However how do you nicely see if something

8条回答
  •  半阙折子戏
    2021-02-05 00:22

    What about disjoint ?

    def elements = [1, 2, 3]
    def element = 4
    assert elements.disjoint([element])
    element = 1
    assert !elements.disjoint([element])
    

    Bonus : it stops iterating when an element match

提交回复
热议问题