Java 实例 - 遍历 HashTable 的键值

Java 教程 · 2019-02-11 18:44:26

以下实例演示了如何使用 Hashtable 类的 keys() 方法来遍历输出键值:

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

以上代码运行输出结果为:

3
2
1

点击查看所有 Java 教程 文章: https://codercto.com/courses/l/12.html

查看所有标签

Data Structures and Algorithms in Java

Data Structures and Algorithms in Java

Robert Lafore / Sams / 2002-11-06 / USD 64.99

Data Structures and Algorithms in Java, Second Edition is designed to be easy to read and understand although the topic itself is complicated. Algorithms are the procedures that software programs use......一起来看看 《Data Structures and Algorithms in Java》 这本书的介绍吧!

MD5 加密
MD5 加密

MD5 加密工具

RGB HSV 转换
RGB HSV 转换

RGB HSV 互转工具

HEX CMYK 转换工具
HEX CMYK 转换工具

HEX CMYK 互转工具