Java ArrayList indexOf example

ArrayList‘s indexOf method is used to find out first index of object in arraylist.

indexOf method takes object as argument and returns first occurrence of specified element.

Methods:

public int indexOf(Object o)
returns index of first occurrence of element in the ArrayList.

indexOf method return -1 if object is not present in the ArrayList

ArrayList indexOf Example:

When you run above program, you will get below output

Was this post helpful?

Leave a Reply

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