Home Tutorial Java Iterator Java Map iterator with example

 
 

Share on Google+Share on Google+
Java Map iterator with example
Posted on: November 2, 2009 at 12:00 AM
Advertisement
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()) {
			System.out.println(i.next());
		}
	}
}

Output

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

Related Tags for Java Map iterator with example:


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.

Posted on: November 2, 2009

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com