Groovy not in collection

前端 未结 8 1161
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:28

    Another way to write it is with contains, e.g.

    if (!['a', 'b', 'c'].contains('b'))
    

    It saves the extra level of parentheses at the cost of replacing the operator with a method call.

提交回复
热议问题