Share on Google+Share on Google+

Java Map iterator with example

In this tutorial we will see how to use the Java Map iterator interface with ArrayList. We will create an example to display the contents of the ArrayList.

  • Java Map Iterator is an interface. It keeps the data in the key and value form.
  • It is implemented by HashMap, Tree Map.
  • Map has no iterator method.
  • So use the entrySet() method to get the data in Set object form.
  • Use the entrySet() method to get the data in Set object form.

Java Map Iterator with Example
import java.util.*;

public class map {
	public static void main(String[] args) {
		Map map = new TreeMap();
		map.put("a", new Integer(1000));
		map.put("b", 2000);
		map.put("c", new Integer(3000));
		map.put("d", new Integer(4000));

		Set s = map.entrySet();
		Iterator i = s.iterator();
		while (i.hasNext()) {


a=1000 b=2000 c=3000 d=4000


Posted on: November 2, 2009 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.