Iterator in HashTable
Previous | Home | Next |
In this program we will see how the iterator is work in the HashTable.
hasmoreElement() and nextelement() method of Hashtable class are used to iterate the values of the table.
Enumeration class is used here.
hasmoreElement() check whether the more elements are present in the table or not .and the nextElement() Move to the next key of the table
hasmoreElement() check whether the more elements are present in the table or not .and the nextElement() Move to the next key of the table
package Example;
import java .util.Enumeration;
import java .util.Hashtable;
public class IterateHashtabl {
public static void main(String[] args) {
Hashtable tb = new Hashtable();
tb.put("5","five");
tb.put("6","Six");
tb.put("7","seven");
Enumeration e =tb.keys();
while (e.hasMoreElements())
System.out.println(e.nextElement());
}
}
6
5
7
Previous | Home | Next |