Groovy - 列表 contains()



如果此列表包含指定值,則返回 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_lists.htm
廣告
© . All rights reserved.