- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- 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 listIterator() method of CopyOnWriteArrayList in Java starting at a specified position
The listIterator() method CopyOnWriteArrayList class returns 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.
To work with CopyOnWriteArrayList class, you need to import the following package
import java.util.concurrent.CopyOnWriteArrayList;
The following is an example to implement CopyOnWriteArrayList class listIterator() method in Java. We have set the index as 3, therefore, the list would be iterated from index 3
Example
import java.util.Iterator; import java.util.ListIterator; import java.util.concurrent.CopyOnWriteArrayList; public class Demo { public static void main(String[] args) { CopyOnWriteArrayList<Integer> arrList = new CopyOnWriteArrayList<Integer>(); arrList.add(30); arrList.add(40); arrList.add(60); arrList.add(70); arrList.add(90); arrList.add(100); arrList.add(120); System.out.println("CopyOnWriteArrayList = " + arrList); ListIterator listIterator = arrList.listIterator(3); System.out.println("Iterating over the elements =" ); while (listIterator.hasNext()) { System.out.println(listIterator.next()); } } }
Output
CopyOnWriteArrayList = [30, 40, 60, 70, 90, 100, 120] Iterating over the elements = 70 90 100 120
Advertisements