
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Get Enumeration Over HashSet in Java
To get enumeration over HashSet, first declare the HashSet and add elements −
HashSet<String> hs = new HashSet<String>(); hs.add("P"); hs.add("Q"); hs.add("R");
To get enumeration −
Enumeration e = Collections.enumeration(hs);
The following is an example to get Enumeration over HashSet −
Example
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()); } }
Output
P Q R
Advertisements