How to get the next index of ArrayList using ListIterator in Java

1 Answer

0 votes
package javaapplication1;

import java.util.ArrayList;
import java.util.ListIterator;

public class JavaApplication1 {

    public static void main(String[] args) {

        ArrayList arrList = new ArrayList();
   
        arrList.add("Java");
        arrList.add("C");
        arrList.add("C++");
        arrList.add("C#");
        arrList.add("PHP");
        arrList.add("JavaScript");

        ListIterator li= arrList.listIterator();
    
        System.out.println("Next Index is : " + li.nextIndex());
        
        li.next();

        System.out.println("Next Index is : " + li.nextIndex());
        System.out.println("Next Index is : " + li.nextIndex());
    }
}
 
/*
run:
 
Next Index is : 0
Next Index is : 1
Next Index is : 1
 
*/

 



answered Oct 1, 2016 by avibootz
...