Java Collection Tutorial - Java Hashtable.elements()








Syntax

Hashtable.elements() has the following syntax.

public Enumeration <V> elements()

Example

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

/* ww w. j a  v a2  s . c o m*/

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

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 enumeration
      Enumeration<String> e=htable.elements();
      
      System.out.println("Display result:"); 
    
      // display search result
      while (e.hasMoreElements()) {
         System.out.println(e.nextElement());
      }      
   }    
}

The code above generates the following result.