VOOZH about

URL: https://www.geeksforgeeks.org/java/hashtable-elements-method-in-java/

⇱ Hashtable elements() Method in Java - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Hashtable elements() Method in Java

Last Updated : 2 Jun, 2023

The elements() method in the Hashtable class in Java returns an enumeration of the values contained in the hashtable. The enumeration returned by this method traverses the hashtable's values in the order in which they were added to the hashtable.

The elements() method is inherited from the java.util.Hashtable class's parent class, java.util.Dictionary.

Here's an example of using the elements() method:


Output
30
35
25

The java.util.Hashtable.elements() method of the Hashtable class in Java is used to get the enumeration of the values present in the hashtable. 

Syntax:

Enumeration enu = Hash_table.elements()

Parameters: The method does not take any parameters. 

Return value: The method returns an enumeration of the values of the Hashtable. 

Below programs are used to illustrate the working of the java.util.Hashtable.elements() method: 

Program 1: 

Output:

The Table is: {10=Geeks, 20=Geeks, 30=You, 15=4, 25=Welcomes}
The enumeration of values are:
Geeks
Geeks
You
4
Welcomes

Program 2:

Output:

The Table is: {You=30, Welcomes=25, 4=15, Geeks=20}
The enumeration of values are:
30
25
15
20
Comment