Skip to main content

9. boolean contains(Object o)

9. boolean contains(Object o)
Returns true if this list contains the specified element.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package com.spy.method.LinkedList;
 
import java.util.LinkedList;
 
public class ContainMethod 
{
 
	public static void main(String[] args) 
	{
 
		LinkedList<String> emp_list=new LinkedList<>();
 
		emp_list.add("Bhavesh Lakhani");
		emp_list.add("Abhilash Shah");
		emp_list.add("Nilay Shah");
		emp_list.add("Vaibhav Prajapati");
 
		//This method returns true if element present in Arraylist
		boolean b=emp_list.contains("Bhavesh Lakhani");
 
	    if(b)
	    {
	    	System.out.println("Element present in LinkedList");
	    }
 
	    else
	    {
	    	System.out.println("Element not present in LinkedList");
	    }
 
	}
}

output

1
Element present in LinkedList