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 193 views
2 answers 156 views
156 views asked Feb 16, 2021 by avibootz
1 answer 166 views
1 answer 174 views
1 answer 140 views
140 views asked Feb 16, 2021 by avibootz
1 answer 193 views
193 views asked Sep 26, 2016 by avibootz
...