透過 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