LinkedList indexOf() Method in Java Last Updated : 11 Jul, 2025 Comments Improve Suggest changes 5 Likes Like Report In Java, the indexOf() method of the LinkedList class is used to find the index of the first occurrence of the specified element in the list. Syntax of LinkedList indexOf() Method public int indexOf(Object o);Parameter: This method takes an object "o" as an argument.Return type: It returns the index of the first occurrence of the specified element.If the element is not present, it will return -1.Example: Here, we use the indexOf() method to find the index of the specified element in the list. Java // Java Program to Demonstrate the // use of indexOf() in the LinkedList import java.util.LinkedList; public class Geeks { public static void main(String args[]) { // Create an empty list LinkedList<Integer> l = new LinkedList<>(); // Use add() method to add // elements in the list l.add(10); l.add(20); l.add(30); l.add(40); l.add(50); System.out.println("The LinkedList is: " + l); // Use indexOf() to return // the index of an element System.out.println( "The first occurrence of 20 is at index:" + l.indexOf(20)); System.out.println( "The first occurrence of 90 is at index: " + l.indexOf(90)); } } OutputThe LinkedList is: [10, 20, 30, 40, 50] The first occurrence of 20 is at index:1 The first occurrence of 90 is at index: -1 Points to Remember:The index returned is zero-based, meaning the first element has an index of 0.If the list contains duplicate elements, indexOf() returns the index of the first occurrence.If the specified element is null, the method can handle it if the list allows null elements. Create Quiz Comment C chinmoy lenka Follow 5 Improve C chinmoy lenka Follow 5 Improve Article Tags : Misc Java Java-Collections Java - util package Java-Functions java-LinkedList +2 More Explore Java BasicsIntroduction to Java3 min readJava Programming Basics9 min readJava Methods6 min readAccess Modifiers in Java4 min readArrays in Java7 min readJava Strings7 min readRegular Expressions in Java3 min readOOP & InterfacesClasses and Objects in Java5 min readAccess Modifiers in Java4 min readJava Constructors4 min readJava OOP(Object Oriented Programming) Concepts10 min readJava Packages2 min readJava Interface7 min readCollectionsCollections in Java12 min readCollections Class in Java13 min readCollection Interface in Java4 min readIterator in Java4 min readJava Comparator Interface5 min readException HandlingJava Exception Handling6 min readJava Try Catch Block4 min readJava final, finally and finalize4 min readChained Exceptions in Java3 min readNull Pointer Exception in Java5 min readException Handling with Method Overriding in Java4 min readJava AdvancedJava Multithreading Tutorial3 min readSynchronization in Java7 min readFile Handling in Java4 min readJava Method References7 min readJava 8 Stream Tutorial7 min readJava Networking6 min readJDBC Tutorial5 min readJava Memory Management3 min readGarbage Collection in Java6 min readMemory Leaks in Java3 min readPractice JavaJava Interview Questions and Answers15+ min readJava Programs - Java Programming Examples7 min readJava Exercises - Basic to Advanced Java Practice Programs with Solutions5 min readJava Quiz1 min readJava Project Ideas For Beginners and Advanced15+ min read Like