A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.tutorialspoint.com/javaexamples/collection_enumeration.htm below:

How to use enumeration to display contents of HashTable in Java

How to use enumeration to display contents of HashTable in Java Problem Description

How to use enumeration to display contents of HashTable?

Solution

Following example uses hasMoreElements & nestElement Methods of Enumeration Class to display the contents of the HashTable.

import java.util.Enumeration;
import java.util.Hashtable;

public class Main {
   public static void main(String[] args) {
      Hashtable ht = new Hashtable();
      ht.put("1", "One");
      ht.put("2", "Two");
      ht.put("3", "Three");
      Enumeration e = ht.elements();
      
      while(e.hasMoreElements()) {
         System.out.println(e.nextElement());
      }
   }
}
Result

The above code sample will produce the following result.

Three
Two
One

java_collections.htm


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4