通过 Java 获取 HashSet 上的枚举
要通过 HashSet 获取枚举,首先声明 HashSet 并添加元素 -
HashSet<String> hs = new HashSet<String>();
hs.add("P");
hs.add("Q");
hs.add("R");要获取枚举 -
Enumeration e = Collections.enumeration(hs);
以下是一个通过 HashSet 获取枚举的示例 -
示例
import java.util.*;
public class Demo {
public static void main(String[] args) {
HashSet<String> hs = new HashSet<String>();
hs.add("P");
hs.add("Q");
hs.add("R");
Enumeration e = Collections.enumeration(hs);
while (e.hasMoreElements())
System.out.println(e.nextElement());
}
}输出
P Q R
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP