Monday, 29 May 2017

Traverse linked list using enumeration

package javaRadarLinkedList;

import java.util.Collections;
import java.util.Enumeration;
import java.util.LinkedList;

public class EnumerationTraversal {

      public static void main(String[] args) {
            //create Linked List
            LinkedList<String> javaRadarList = new LinkedList<String>();
            //Add elements to LinkedList
            javaRadarList.add("Java");
            javaRadarList.add("Jquery");
            javaRadarList.add("Spring");
            javaRadarList.add("Hibernate");
            javaRadarList.add("EJB");

            //creating iterator 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());
            }
      }

}


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.