Search Element in the LinkedList

In the previous post, we have seen how to remove all elements from the List. In this post, we will see how to search Element in the LinkedList.

We can use the following methods for searching elements.


public int indexOf(Object o):  Returns the index of the first occurrence of the specified element in this list, or -1 if the element.

public int lastIndexOf(Object o): Returns the index of the last occurrence of the specified element in this list, or -1 if this list does not contain the element.



Find out first occurrence of Mango :1
Find out last occurrence of Grapes :6


Have any question or suggestion for us?Please feel free to post in Q&A Forum
Print Friendly, PDF & Email
Remove all elements from LinkedList
Get subList from LinkedList
Shekhar Sharma

Shekhar Sharma

Shekhar Sharma is founder of He is an automation engineer having more than 8 years of experience who loves troubleshooting in automation and finding innovative ways to solve the problems. His other leisurely activities includes playing harmonica, paintings, sketching portrait, watching movies and travelling etc.

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *