當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Groovy contains()用法及代碼示例


檢查範圍是否包含特定值。

用法

boolean contains(Object obj)

參數

Obj─ 要在範圍列表中檢查的值。

返回值

如果此 Range 包含指定的元素,則返回 true。

示例

以下是此方法的使用示例~

class Example { 
   static void main(String[] args) { 
      // Example of an Integer using def 
      def rint = 1..10; 
		
      println(rint.contains(2)); 
      println(rint.contains(11)); 
   } 
}

當我們運行上麵的程序時,我們會得到以下結果——

true 
false

相關用法


注:本文由純淨天空篩選整理自 Groovy - contains()。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。