Home » Java programming language

Java LinkedList boolean contains(Object o) method with Example

Java LinkedList boolean contains(Object o) method: Here, we are going to learn about the boolean contains(Object o) method of LinkedList class with its syntax and example.
Submitted by Preeti Jain, on June 17, 2019

LinkedList boolean contains(Object o) method

  • This method is available in package java.util.Collection and here, Collection is an interface.
  • This method is declared in interface Collection and implemented by the LinkedList Class.
  • This method is used to check or identify whether an element or Object exists or not in the Linked list.
  • In this method, if Object exists in the linked list then it returns true else false.


    boolean  contains(Object o){


This method accepts one parameter.

Return value:

The return type of this method is boolean that means this method returns true if the searched element is present in the linked list else it will return false after execution.

Java program to demonstrate example of LinkedList contains(Object o) method

import java.util.LinkedList;

public class LinkList {
 public static void main(String[] args) {

  // Create an object of linked list 
  LinkedList list = new LinkedList();

  // use add() method to add few elements in the linked list 

  //  Current Linked list Output
  System.out.println("The  Current Linked List is :" + list);

  // With the help of contains(Object o) we will check 
  // whether 20 exists or not exists in the linked list. 

  System.out.println("The contains() will return or false : " + list.contains(20));


D:\Programs>javac LinkList.java

D:\Programs>java LinkList
The  Current Linked List is :[10, 20, 30, 40, 50]
The Searching Element is:true

Comments and Discussions!

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.