java.util.Hashtable.entrySet() Method

Advertisements


Description

The entrySet() method is used to get a set view of the entries contained in this Hashtable.Remember, each element in this collection is a Map.Entry.

Declaration

Following is the declaration for java.util.Hashtable.entrySet() method.

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

Parameters

  • NA

Return Value

The method call returns a set view of the mappings contained in this map.

Exception

  • NA

Example

The following example shows the usage of java.util.Hashtable.entrySet()

package com.tutorialspoint;

import java.util.*;

public class HashTableDemo {
   public static void main(String args[]) {
      // create hash table 
      Hashtable htable = new Hashtable();
      
      // put values into the table
      htable.put(1, "A");
      htable.put(2, "B");
      htable.put(3, "C");
      htable.put(4, "D");
      
      // create a set view
      Set nset=htable.entrySet();
      
      // display set result
      System.out.println("Set result:"+nset); 
   }    
}

Let us compile and run the above program, this will produce the following result.

Set result:[4=D, 3=C, 2=B, 1=A]



Advertisements
Advertisements