- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
The indexOf() method of AbstractList class in Java
The indexOf() method is used to return the index of the first occurrence of the specified element in this list. If the list is empty, it returns -1.
The syntax is as follows.
int indexOf(Object ob)
Here, the parameter ob is the element to search for.
To work with the AbstractList class, import the following package.
import java.util.AbstractList;
The following is an example to implement indexOf() method of the AbstractlList class in Java.
Example
import java.util.ArrayList; import java.util.AbstractList; public class Demo { public static void main(String[] args) { AbstractList<Integer> myList = new ArrayList<Integer>(); myList.add(5); myList.add(20); myList.add(35); myList.add(47); myList.add(55); myList.add(70); myList.add(100); myList.add(140); myList.add(100); myList.add(250); System.out.println("Elements in AbstractList = " + myList); System.out.println("Last Index of the element 100 = " + myList.lastIndexOf(100)); } }
Output
Elements in AbstractList = [5, 20, 35, 47, 55, 70, 100, 140, 100, 250] Last Index of the element 100 = 8
- Related Articles
- The indexOf() method of CopyOnWriteArrayList class in Java
- The addAll() method of AbstractList class in Java
- The lastIndexOf() method of AbstractList class in Java
- The subList() method of AbstractList class in Java
- The equals() method of AbstractList class in Java
- The clear() method of AbstractList class in Java
- The iterator() method of AbstractList class in Java
- The listIterator() method of AbstractList class in Java
- The get() method of AbstractList class in Java
- The set() method of AbstractList class in Java
- The hashCode() method of AbstractList class in Java
- The remove() method of AbstractList class in Java
- The listIterator() method AbstractList class in Java at a specified position
- The indexOf() method of AbstractSequentialList in Java
- What is AbstractList Class in Java?

Advertisements