Home > Java > javaTutorial > Java Example - Traversing HashTable using Enumeration

Java Example - Traversing HashTable using Enumeration

黄舟
Release: 2017-01-22 15:13:40
Original
1412 people have browsed it

The following example demonstrates how to use the hasMoreElements and nestElement methods of the Enumeration class to traverse and output the contents of the HashTable:

/*
 author by w3cschool.cc
 Main.java
 */

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());
      }
   }
}
Copy after login

The output result of running the above code is:

Three
Two
One
Copy after login

The above is the Java example - Use Enumeration to traverse the contents of HashTable. For more related content, please pay attention to the PHP Chinese website (www.php.cn)!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template