YouTip LogoYouTip

Collection Iterate

# Java Example - HashMap Iteration [![Image 3: Java Example](#) Java Example](#) The following example demonstrates how to use the iterator() method of the Collection class to iterate through a collection: ## Main.java File import java.util.*; public class Main{public static void main(String[]args){HashMaphMap = new HashMap(); hMap.put("1", "1st"); hMap.put("2", "2nd"); hMap.put("3", "3rd"); Collection cl = hMap.values(); Iterator itr = cl.iterator(); while(itr.hasNext()){System.out.println(itr.next()); }}} The output of the above code is: 1st2nd3rd [![Image 4: Java Example](#) Java Example](#)
← Collection MinmaxData Queue β†’