![]() |
VOOZH | about |
The contains() method of List interface in Java is used for checking if the specified element exists in the given list or not.
Example:
List contains 2 : true List contains 3 : false
public boolean contains(Object obj)
Practical Application : In search operations, we can check if a given element exists in a list or not.
Below programs illustrate the contains() method in List:
Program 1: Demonstrate the working of the method contains() in List of integer.
The list contains 2 The list does not contains 5
Program 2: Demonstrate the working of the method contains() in List of string.
The list contains geeks The list does not contains coding
Reference: Click here to check the official document