ArrayList.contains()

ArrayList

ArrayList.contains(search_element) Searching for presence of elements in an ArrayList.
search_element : Required , element to be searched inside ArrayList.
Boolean : Returns true of at least one match is found, false otherwise.

add()
Examples with output
ArrayList<String> languages = new ArrayList<String>();
languages.add("Java");
languages.add("PHP");
languages.add("Python");
System.out.println(languages); //[Java, PHP, Python]

if(languages.contains("PHP")) {
	System.out.println(" PHP is available");	
}else {
	System.out.println(" PHP is NOT available");
}
Output
[Java, PHP, Python]
 PHP is available
Example :
ArrayList<Integer> marks = new ArrayList<Integer>();
marks.add(55);
marks.add(54);
marks.add(60);
System.out.println(marks); 

if(marks.contains(54)) {
	System.out.println(" 54  is available");	
}else {
	System.out.println(" 54 is NOT available");
}
Output
[55, 54, 60]
 54  is available
ArrayList Tutorials



plus2net.com



Post your comments , suggestion , error , requirements etc here




We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
©2000-2020 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer