Home > Java > Java Tutorial > body text

Java Example - Traverse the key values ​​of HashTable

黄舟
Release: 2017-01-22 15:12:05
Original
1380 people have browsed it

The following example demonstrates how to use the keys() method of the Hashtable class to traverse the output key values:

/*
 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.keys();
      while (e.hasMoreElements()){
         System.out.println(e.nextElement());
      }
   }
}
Copy after login

The output result of running the above code is:

3
2
1
Copy after login

above It is a Java example - traversing the key value content of HashTable. For more related content, please pay attention to the PHP Chinese website (m.sbmmt.com)!

Related labels:
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!