Traverse through ArrayList in reverse direction using ListIterator - Java Collection Framework

Java examples for Collection Framework:ListIterator

Description

Traverse through ArrayList in reverse direction using ListIterator

Demo Code


import java.util.ListIterator;
import java.util.ArrayList;
 
public class Main {
 
  public static void main(String[] args) {
    ArrayList aList = new ArrayList();
   //from w w w . ja  va2 s. c  o  m
    aList.add("1");
    aList.add("2");
    aList.add("3");
    aList.add("4");
    aList.add("5");
   
    ListIterator listIterator = aList.listIterator();
 
    while(listIterator.hasNext()){
      System.out.println(listIterator.next());
    }
    while(listIterator.hasPrevious()){
      System.out.println(listIterator.previous());
    }
  }
}

Result


Related Tutorials