Online Java Compiler By
JavaTpoint.com
import java.util.ArrayList; import java.util.ListIterator; public class JavaListIteratornextIndexExample3 { public static void main(String[] args) { ArrayList < Integer > marks= new ArrayList < Integer > (); marks.add(5); marks.add(10); marks.add(15); marks.add(20); System.out.println("The ages are listed as :"+marks); ListIterator < Integer > listIterator = marks.listIterator(); System.out.println("The first Index is given as : " + listIterator.nextIndex()); listIterator.next(); System.out.println("The second Index is given as : " + listIterator.nextIndex()); listIterator.next(); System.out.println("The third index is given as : " + listIterator.nextIndex()); listIterator.next(); System.out.println("The fourth index is given as : " + listIterator.nextIndex()); } }
Output