Java Collection Tutorial - Java Hashtable.entrySet()








Syntax

Hashtable.entrySet() has the following syntax.

public Set <Map.Entry <K, V>> entrySet()

Example

In the following code shows how to use Hashtable.entrySet() method.

//  w  ww.  j  a  v a  2 s.co m
import java.util.Hashtable;
import java.util.Map.Entry;
import java.util.Set;

public class Main {
   public static void main(String args[]) {
      Hashtable<Integer, String> htable = new Hashtable<Integer, String>();

      // put values into the table
      htable.put(1, "A");
      htable.put(2, "B");
      htable.put(3, "C");
      htable.put(4, "from java2s.com");

      
      // create a set view
      Set<Entry<Integer, String>> nset=htable.entrySet();
      
      // display set result
      System.out.println("Set result:"+nset); 
   }    
}

The code above generates the following result.