Groovy - Lists contains()

如果此 List 包含指定的值,则返回 true。


语法

boolean contains(Object value)

参数

Value − 要在列表中查找的值。


返回值

True 或 false 决于值是否存在于列表中。


示例

以下是该方法的用法示例 −

class Example { 
   static void main(String[] args) { 
      def lst = [11, 12, 13, 14]; 
		
      println(lst.contains(12)); 
      println(lst.contains(18));
   }
}

当我们运行上面的程序时,会得到下面的结果 −

true 
false

❮ Groovy 列表