java.util.ArrayList.contains(Object) method
来源:互联网 发布:最新的网络流行语 编辑:程序博客网 时间:2024/06/05 09:15
描述
The java.util.ArrayList.contains(Object) method returns true if this list contains the specified element.
声明
Following is the declaration for java.util.ArrayList.contains() method
public boolean contains(Object o)
参数
o -- The element whose presence in this list is to be tested.
返回值
This method returns true if this list contains the specified element.
异常
NA
实例一编辑+分享实例
以下例子将告诉你如何使用 java.util.Arraylist.contains method.
package yiibai.com;
import java.util.ArrayList;
public class ArrayListDemo {
public static void main(String[] args) {
// create an empty array list with an initial capacity
ArrayList<Integer> arrlist = new ArrayList<Integer<(8);
// use add() method to add elements in the list
arrlist.add(20);
arrlist.add(25);
arrlist.add(10);
arrlist.add(15);
// let us print all the elements available in list
for (Integer number : arrlist) {
System.out.println("Number = " + number);
}
// list contains element 10
boolean retval = arrlist.contains(10);
if (retval == true) {
System.out.println("element 10 is contained in the list");
}
else {
System.out.println("element 10 is not contained in the list");
}
// list does not contain element 30
boolean retval2 = arrlist.contains(30);
if (retval2 == true) {
System.out.println("element 30 is contained in the list");
}
else {
System.out.println("element 30 is not contained in the list");
}
}
}
编译和执行以上程序,将得到以下的结果:
Number = 20
Number = 25
Number = 10
Number = 15
element 10 is contained in the list
element 30 is not contained in the list
The java.util.ArrayList.contains(Object) method returns true if this list contains the specified element.
声明
Following is the declaration for java.util.ArrayList.contains() method
public boolean contains(Object o)
参数
o -- The element whose presence in this list is to be tested.
返回值
This method returns true if this list contains the specified element.
异常
NA
实例一编辑+分享实例
以下例子将告诉你如何使用 java.util.Arraylist.contains method.
package yiibai.com;
import java.util.ArrayList;
public class ArrayListDemo {
public static void main(String[] args) {
// create an empty array list with an initial capacity
ArrayList<Integer> arrlist = new ArrayList<Integer<(8);
// use add() method to add elements in the list
arrlist.add(20);
arrlist.add(25);
arrlist.add(10);
arrlist.add(15);
// let us print all the elements available in list
for (Integer number : arrlist) {
System.out.println("Number = " + number);
}
// list contains element 10
boolean retval = arrlist.contains(10);
if (retval == true) {
System.out.println("element 10 is contained in the list");
}
else {
System.out.println("element 10 is not contained in the list");
}
// list does not contain element 30
boolean retval2 = arrlist.contains(30);
if (retval2 == true) {
System.out.println("element 30 is contained in the list");
}
else {
System.out.println("element 30 is not contained in the list");
}
}
}
编译和执行以上程序,将得到以下的结果:
Number = 20
Number = 25
Number = 10
Number = 15
element 10 is contained in the list
element 30 is not contained in the list
- java.util.ArrayList.contains(Object) method
- java.util.ArrayList#contains(Object o)
- java.util.ArrayList.indexOf(Object) 方法
- Java ArrayList contains details.
- SQLException: Invalid parameter object type. Expected 'java.util.ArrayList' but found 'java.util.Ar
- Invoke interface method 'java.lang.Object[]java.util.Collection.toArray()'on a null object reference
- java.util.ArrayList学习
- java.util.ArrayList
- JAVA.Util.ArrayList
- java.util.ArrayList size()
- 【源代码】java.util.ArrayList
- 11 java.util.ArrayList
- java.util.ArrayList 源码
- Java-Util之ArrayList
- java.util.ArrayList<E>
- java.util.ArrayList
- java.util.ArrayList
- java.util.ArrayList
- 分享一个自己写的flash位图转换类
- ACM hdu1175 连连看
- 使用cygwin和NDK编译Android版本的libevent
- 记录一点点002
- 正则表达式基础
- java.util.ArrayList.contains(Object) method
- android瀑布流效果(仿蘑菇街)
- mybatis使用map传入多个参数
- Unable to find a result type for extension [...] in location attribute
- Convert Sorted List to Binary Search Tree
- 北大校赛2011 Word Ladder(C题) 解题报告
- 【Cocos2d-x 004】 在Mac下结合Xcode搭建Cocos2d-X开发环境!
- 【hdu2243】【AC自动机】【矩阵乘法】考研路茫茫——单词情结
- CCFileUtils::sharedFileUtils()->setResourceDirectory(dir) 方法的更新