java.util.Hashtable.keySet() Method
Advertisements
Description
The keySet() method is used to get a Set view of the keys contained in this Hashtable.
Declaration
Following is the declaration for java.util.Hashtable.keySet() method.
public Set<K> keySet()
Parameters
NA
Return Value
The method call returns a set view of the keys contained in this map.
Exception
NA
Example
The following example shows the usage of java.util.Hashtable.keySet()
package com.tutorialspoint;
import java.util.*;
public class HashTableDemo {
public static void main(String args[]) {
// create hash table
Hashtable htable1 = new Hashtable();
// put values in table
htable1.put(1, "A");
htable1.put(2, "B");
htable1.put(3, "C");
htable1.put(4, "D");
// create a set view
Set st=htable1.keySet();
System.out.println("Display result: "+st);
}
}
Let us compile and run the above program, this will produce the following result.
Display result: [4, 3, 2, 1]