Share on Google+Share on Google+

Java Hashtable Iterator

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()) {



Posted on: November 3, 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.


Advertisement null