packagejavaRadarArrayList;
importjava.util.ArrayList;
importjava.util.Collections;
importjava.util.Enumeration;
import java.util.ListIterator;
public classEnumerationTraversal {
      public static void main(String[] args) {
            //create Array List
            ArrayList<String> javaRadarList = newArrayList<String>();
            //Add elements to ArrayList
            javaRadarList.add(“Java”);
            javaRadarList.add(“Jquery”);
            javaRadarList.add(“Spring”);
            javaRadarList.add(“Hibernate”);
            javaRadarList.add(“EJB”);
            //creating enumeration to traverse over javaRadarList
            Enumeration<String> listEnumerator = Collections.enumeration(javaRadarList);
            System.out.println(“List traversal using Enumeration”);
            while(listEnumerator.hasMoreElements()){
                  System.out.println(listEnumerator.nextElement());
            }
      }
}

OUTPUT:
List traversal using Enumeration
Java
Jquery
Spring
Hibernate
EJB

Source link

Traverse ArrayList using Enumeration

2 thoughts on “Traverse ArrayList using Enumeration

Leave a Reply

Your email address will not be published. Required fields are marked *