public boolean contains(Object) object-element to be searched for
object- element whose presence in this list is to be tested
It returns true if the specified element is found in the list else it returns false.
Code#1: Demonstrate the working of the method contains() in integer
The list contains 2 The list does not contains 5
Code#2: Demonstrate the working of the method contains() in string
The list contains geeks The list does not contains coding
In search operations, we can check if a given element exists in a list or not.
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
- Java String toLowerCase() with examples
- Arrays.sort() in Java with examples
- List Interface in Java with Examples
- Java.util.Hashtable Class in Java
- Collections.sort() in Java with Examples
- HashSet vs TreeSet in Java
- ShortBuffer allocate() method in Java With Examples
- IntBuffer duplicate() method in Java with Examples
- ShortBuffer compact() method in Java With Examples
- LongBuffer equals() method in Java