Home Tutorial Java Iterator Java Hashtable Iterator

 
 

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()) {
			System.out.println(it.next());
		}
	}
}

Output:

Related Tags for Java Hashtable Iterator: