檢查範圍是否包含特定值。
用法
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 concat()用法及代碼示例
- Groovy collect()用法及代碼示例
- Groovy compareTo()用法及代碼示例
- Groovy compareToIgnoreCase()用法及代碼示例
- Groovy cos()用法及代碼示例
- Groovy ceil()用法及代碼示例
- Groovy matches()用法及代碼示例
- Groovy after()用法及代碼示例
- Groovy padRight()用法及代碼示例
- Groovy exp()用法及代碼示例
- Groovy equals()用法及代碼示例
- Groovy before()用法及代碼示例
- Groovy pow()用法及代碼示例
- Groovy sin()用法及代碼示例
注:本文由純淨天空篩選整理自 Groovy - contains()。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。