- 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 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
- Related Articles
- The listIterator() method AbstractList class in Java at a specified position
- Insert the specified element at the specified position in Java CopyOnWriteArrayList
- The listIterator() method of CopyOnWriteArrayList in Java
- The isEmpty() method of CopyOnWriteArrayList method in Java
- The hashCode() method of CopyOnWriteArrayList method in Java
- The clone() method of CopyOnWriteArrayList method in Java
- Java Program to remove a character at a specified position
- The contains() method of CopyOnWriteArrayList in Java
- The add() method of CopyOnWriteArrayList in Java
- The toString() method of CopyOnWriteArrayList in Java
- The set() method of CopyOnWriteArrayList in Java
- The addIfAbsent() method of CopyOnWriteArrayList in Java
- The iterator() method of CopyOnWriteArrayList in Java
- The lastIndexOf() method of CopyOnWriteArrayList in Java
- The get() method of CopyOnWriteArrayList in Java

Advertisements