VOOZH about

URL: https://www.geeksforgeeks.org/java/abstractlist-indexof-method-in-java-with-examples/

⇱ AbstractList indexOf() method in Java with Examples - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

AbstractList indexOf() method in Java with Examples

Last Updated : 11 Jul, 2025
The indexOf() method of java.util.AbstractList class is used to return the index of the first occurrence of the specified element in this list, or -1 if this list does not contain the element. More formally, returns the lowest index i such that (o==null ? get(i)==null : o.equals(get(i))), or -1 if there is no such index. Syntax:
public int indexOf(Object o)
Parameters: This method takes Object o as parameter which is the element to search for. Return Value: This method returns the index of the first occurrence of the specified element in this list, or -1 if this list does not contain the element. Below are the examples to illustrate the indexOf() method. Example 1:
Output:
ArrayListlist : [10, 20, 30, 40, 50]
index : 2
Example 2:
Output:
ArrayListlist : [10, 20, 30, 40, 50]
Index of 25 : -1
Example 3: For Null value
Output:
ArrayListlist : [10, 20, 30, 40, 50]
Index of null : -1
Comment