How to get enumeration over HashSet in Java

1 Answer

0 votes
package javaapplication1;

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

public class JavaApplication1 {

    public static void main(String[] args) {

        HashSet hashSet = new HashSet();
   
        hashSet.add("a");
        hashSet.add("b");
        hashSet.add("c");
        hashSet.add("d");
        hashSet.add("e");
        hashSet.add("f");
        hashSet.add("g");

        Enumeration e = Collections.enumeration(hashSet);

        while (e.hasMoreElements()) 
            System.out.println(e.nextElement());
  }
}
  
/*
run:

a
b
c
d
e
f
g

*/

 



answered Sep 25, 2016 by avibootz

Related questions

1 answer 265 views
2 answers 254 views
254 views asked Feb 16, 2021 by avibootz
1 answer 258 views
1 answer 246 views
1 answer 209 views
209 views asked Feb 16, 2021 by avibootz
1 answer 267 views
267 views asked Sep 26, 2016 by avibootz
...