java.util.Hashtable.elements() Method


Description

The elements() method is used to return an enumeration of the values in this hashtable.

Declaration

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

public Enumeration<V> elements()

Parameters

NA

Return Value

The method call returns an enumeration of the values in this hashtable.

Exception

NA

Example

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

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 enumeration
      Enumeration e = htable.elements();

      System.out.println("Display result:"); 

      // display search result
      while (e.hasMoreElements()) {
         System.out.println(e.nextElement());
      }      
   }    
}

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

Display result:
D
C
B
A
java_util_hashtable.htm
Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements