Hashtable.keySet() has the following syntax.
public Set <K> keySet()
In the following code shows how to use Hashtable.keySet() method.
/*from w w w . j a v a 2 s. c om*/ import java.util.Hashtable; import java.util.Set; public class Main { public static void main(String args[]) { // create hash table Hashtable<Integer,String> htable1 = new Hashtable<Integer,String>(); // put values in table htable1.put(1, "A"); htable1.put(2, "B"); htable1.put(3, "C"); htable1.put(4, "from java2s.com"); // create a set view Set st=htable1.keySet(); System.out.println("Display result: "+st); } }
The code above generates the following result.