Home Tutorial Java Iterator Java Hashtable Iterator


Share on Google+Share on Google+
Java Hashtable Iterator
Posted on: November 3, 2009 at 12:00 AM
In this section of tutorial we will learn how to use the Hashtable with the Iterator interface. We will create an example to display the contents of the hashtable using Iterator

  • This collection belongs to Map interface family.
  • It puts the data in the key and value form.
  • Like hasmap, it has no iterator() method.
  • Use the entrySet() method.It returns the data in Set object form.
  • Set's all elements can be traversed by the Iterator.

Java Hashtable Iterator Example
import java.util.*;

public class hashtable {

	public static void main(String[] args) {
		Hashtable hastab = new Hashtable();
		hastab.put("a", "andrews");
		hastab.put("b", "bob");
		hastab.put("c", "christina");
		hastab.put("d", "dude");
		hastab.put("e", "era");
		Set s = hastab.entrySet();
		Iterator it = s.iterator();

		while (it.hasNext()) {



Related Tags for Java Hashtable Iterator:

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 3, 2009

Recommend the tutorial

Advertisements Advertisements