Groovy Lists contains()方法

2018-12-29 15:50 更新

如果此列表包含指定的值,則返回true。

句法

boolean contains(Object value)

參數(shù)

- 在列表中查找的值。

返回值

True或false,取決于值是否在列表中存在。

例子

下面是一個(gè)使用這個(gè)方法的例子 -

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

當(dāng)我們運(yùn)行上面的程序,我們將得到以下結(jié)果 -

true 
false
以上內(nèi)容是否對(duì)您有幫助:
在線(xiàn)筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號(hào)
微信公眾號(hào)

編程獅公眾號(hào)