packagejavaRadarLinkedList;
importjava.util.Iterator;
importjava.util.LinkedList;
public class ItrTraversal {
      public static void main(String[] args) {
            //create Linked List
            LinkedList<String> javaRadarList = newLinkedList<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
            Iterator<String> listIterator = javaRadarList.iterator();
            System.out.println(“Traversal in forward direction”);
            while(listIterator.hasNext()){
                  System.out.println(listIterator.next());
            }
      }
}

OUTPUT:
Traversal in forward direction
Java
Jquery
Spring
Hibernate
EJB 

Source link

Traverse Linked list using iterator

Leave a Reply

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