- 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 AbstractSequentialList in Java
The indexOf() method is inherited from the AbstractList class. It 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 −
public int indexOf(Object ele)
Here, ele is the element for which you want the index.
To work with the AbstractSequentialList class in Java, you need to import the following package −
import java.util.AbstractSequentialList;
The following is an example to implement AbstractSequentialList indexOf() method in Java −
Example
import java.util.LinkedList; import java.util.AbstractSequentialList; public class Demo { public static void main(String[] args) { AbstractSequentialList<Integer> absSequential = new LinkedList<>(); absSequential.add(110); absSequential.add(320); absSequential.add(400); absSequential.add(550); absSequential.add(600); absSequential.add(700); absSequential.add(900); System.out.println("Elements in the AbstractSequentialList = "+absSequential); System.out.println("Elements in the AbstractSequentialList = "+absSequential.indexOf(550)); } }
Output
Elements in the AbstractSequentialList = [110, 320, 400, 550, 600, 700, 900] Elements in the AbstractSequentialList = 3
Let us see another example wherein the element does not exist −
Example
import java.util.LinkedList; import java.util.AbstractSequentialList; public class Demo { public static void main(String[] args) { AbstractSequentialList<Integer> absSequential = new LinkedList<>(); absSequential.add(110); absSequential.add(320); absSequential.add(400); absSequential.add(550); absSequential.add(600); absSequential.add(700); absSequential.add(900); System.out.println("Elements in the AbstractSequentialList = "+absSequential); System.out.println("Elements in the AbstractSequentialList = "+absSequential.indexOf(10)); } }
Output
Elements in the AbstractSequentialList = [110, 320, 400, 550, 600, 700, 900] Elements in the AbstractSequentialList = -1
- Related Articles
- The contains() method of AbstractSequentialList in Java
- The clear() method of AbstractSequentialList in Java
- The toArray() method of AbstractSequentialList in Java
- The isEmpty() method of AbstractSequentialList in Java
- The subList() method of AbstractSequentialList in Java
- The equals() method of AbstractSequentialList in Java
- The containsAll() method of AbstractSequentialList in Java
- The removeAll() method of AbstractSequentialList in Java
- The indexOf() method of CopyOnWriteArrayList class in Java
- The indexOf() method of AbstractList class in Java
- The toArray(T[]) method of AbstractSequentialList in Java
- The listIterator() method of Java AbstractSequentialList class
- The remove() method of Java AbstractSequentialList class
- The get() method of Java AbstractSequentialList class
- The set() method of Java AbstractSequentialList class

Advertisements