检查范围是否包含特定值。
句法
- boolean contains(Object obj)
参数
Obj - 要在范围列表中检查的值。
返回值
如果此范围包含指定的元素,则返回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
转载本站内容时,请务必注明来自W3xue,违者必究。