In this section of tutorial we will learn how to use the HashNext method of the Iterator interface. We will create an example to display the contents of the ArrayList using hashNext
In this section of tutorial we will learn how to use the HashNext method of the Iterator interface. We will create an example to display the contents of the ArrayList using hashNext
import java.util.ArrayList; import java.util.Iterator; public class hasnext { public static void main(String[] args) { String months[] = { "jan", "feb", "march", "april", "may", "june" }; ArrayList list = new ArrayList(); for (String m : months) { list.add(m); } Iterator iterator = list.iterator(); while (iterator.hasNext()) { System.out.println(iterator.next()); } } }
Output
jan feb march april may june