Tuesday 23 May 2017

Traverse ArrayList using Iterator

package javaRadarArrayList;

import java.util.ArrayList;
import java.util.Iterator;

public class ItrTraversal {

      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 iterator to traverse over javaRadarList
            Iterator<String> listIterator = javaRadarList.iterator();

            while(listIterator.hasNext()){
                  System.out.println(listIterator.next());
            }
      }

}

OUTPUT:
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.