Wednesday, 31 May 2017

Traverse ArrayList using Enumeration

package javaRadarArrayList;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Enumeration;
import java.util.ListIterator;

public class EnumerationTraversal {

      public static void main(String[] args) {
            //create Array List
            ArrayList<String> javaRadarList = new ArrayList<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


No comments:

Post a Comment

-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
If you are looking for a reference book on java then we recommend you to go for → Java The Complete Reference
Click on the image link below to get it now.