Get Enumeration over HashSet - Java Collection Framework

Java examples for Collection Framework:HashSet

Description

Get Enumeration over HashSet

Demo Code


import java.util.Enumeration;
import java.util.HashSet;
import java.util.Collections;
 
public class Main {
 
  public static void main(String[] args) {
    HashSet hashSet = new HashSet();
   //from w  w  w.j  a  va2 s  .c  o m
    hashSet.add("A");
    hashSet.add("B");
    hashSet.add("D");
    hashSet.add("E");
    hashSet.add("F");
 
    Enumeration e = Collections.enumeration(hashSet);
   
    System.out.println("Enumerating through Java HashSet");
    while(e.hasMoreElements())
      System.out.println(e.nextElement());
  }
}

Result


Related Tutorials