Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- 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 listIterator() method AbstractList class in Java at a specified position
The listIterator() method of the AbstractList class in Java is used to return a list iterator over the elements in this list, beginning at the specified position in the list.
The syntax is as follows.
public ListIterator<E> listIterator(int index)
Here, index is the index of the first element to be returned from the list iterator, whereas, ListIterator<E> is an iterator for lists.
To work with the AbstractList class, import the following package.
import java.util.AbstractList;
For ListIterator, import the following package.
import java.util.ListIterator;
The following is an example to implement listIterator() method of the AbstractlList class in Java.
Example
import java.util.ArrayList;
import java.util.ListIterator;
import java.util.AbstractList;
public class Demo {
public static void main(String[] args) {
AbstractList<Integer> myList = new ArrayList<Integer>();
myList.add(75);
myList.add(100);
myList.add(150);
myList.add(200);
myList.add(250);
myList.add(150);
myList.add(150);
myList.add(400);
System.out.println("Elements in the AbstractList = " + myList);
ListIterator listIterator = myList.listIterator(4);
System.out.println("Iterating over the elements =" );
while (listIterator.hasNext()) {
System.out.println(listIterator.next());
}
}
}
Output
Elements in the AbstractList = [75, 100, 150, 200, 250, 150, 150, 400] Iterating over the elements = 250 150 150 400
Advertisements