首页javasetJava Collection - 如何把HashSet转换为枚举

Java Collection - 如何把HashSet转换为枚举

我们想知道如何把HashSet转换为枚举。
 


import java.util.Collections;
import java.util.Enumeration;
import java.util.HashSet;

public class Main {
  public static void main(String[] args) {
    HashSet<String> hashSet = new HashSet<String>();

    hashSet.add("A");
    hashSet.add("B");
    hashSet.add("D");
    hashSet.add("E");
    hashSet.add("F");

    Enumeration e = Collections.enumeration(hashSet);
    while (e.hasMoreElements())
      System.out.println(e.nextElement());
  }
}