Hashtable keys Example


Hashtable class keys method example. public Enumeration keys() Returns an enumeration of the keys in this hashtable.

Here is the code

/**
 * @ # Keys.java
 * A class repersenting use to Keys method 
 * of HashMap class in java.util package
 * version 19 May 2008
 * author Rose India 
 */
import java.util.*;

public class Keys {

    public static void main(String args[]) {
        Hashtable table = new Hashtable();

        //Put value into the table
        table.put(1"A");
        table.put(2"B");
        table.put(3"C");
        table.put(4"D");

        System.out.println("table :" + table);

        System.out.println("Keys of table are...");
        Enumeration e = table.keys();
        while (e.hasMoreElements()) {
            System.out.println(e.nextElement());
        }
    }
}

Output
table :{4=D, 3=C, 2=B, 1=A}
Keys of table are...
4
3
2
1

Post Comment
Name:
E-mail:
Contact no :
Comments:
  Refresh Image
Verify Image:
 
 
Your Comment's
 
 
 

HOME | COPYRIGHT | CONTACT US