Hashtable keySet Example


Hashtable class keySet method example.public Set keySet() Returns a Set view of the keys contained in this map. The set is backed by the map, so changes to the map are reflected in the set, and vice-versa.

Here is the code

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

public class KeySet {

    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);

        //A Set view of the keys contained in this map
        Set s = table.keySet();
        System.out.println(s);
    }
}

Output
run-single:
table :{4=D, 3=C, 2=B, 1=A}
[4, 3, 2, 1]

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

HOME | COPYRIGHT | CONTACT US