1.Basic java example program to iterate keys of hashtable
Output:
- Enumeration keys() This method used to get keys of hashmap
- package com.iteartekeysHashtable;
- import java.util.Hashtable;
- import java.util.Enumeration;
- public class HashtableExample{
- public static void main(String[] args) {
- //create Hashtable object
- Hashtable<String,String> hashtable = new Hashtable<String,String>();
- //add key value pairs to Hashtable
- hashtable.put("1","Java Interview Questions");
- hashtable.put("2","Java Interview Programs");
- hashtable.put("3","Concept and exampe program");
- hashtable.put("4","Concept and interview Questions");
- hashtable.put("5","Java Quiz");
- hashtable.put("6","Real time examples");
- Enumeration e=hashtable.keys();
- // display search result
- while (e.hasMoreElements()) {
- System.out.println(e.nextElement());
- }
- }
- }
Output:
- 6
- 5
- 4
- 3
- 2
- 1