Iterate through elements ArrayList using ListIterator - Java Collection Framework

Java examples for Collection Framework:ListIterator

Description

Iterate through elements ArrayList using ListIterator

Demo Code


import java.util.ArrayList;
import java.util.ListIterator;
 
public class Main {
 
  public static void main(String[] args) {
   /* ww  w  . j a  v  a2 s  . co  m*/
    ArrayList arrayList = new ArrayList();
    arrayList.add("1");
    arrayList.add("2");
    arrayList.add("3");
    arrayList.add("4");
    arrayList.add("5");
   
    ListIterator itr = arrayList.listIterator();
   
    while(itr.hasNext())
      System.out.println(itr.next());
 
    while(itr.hasPrevious())
      System.out.println(itr.previous());
   
  }
}

Result


Related Tutorials