- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- 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
- Related Articles
- Get Enumeration over ArrayList with Java Collections
- Java Program to convert HashSet to Enumeration
- Iterate over the elements of HashSet in Java
- Get size of HashSet in Java
- Get Synchronized Set from HashSet in Java
- Enumeration in Java
- Comparing Enumeration Values in Java
- HashSet in Java
- The HashSet in Java
- Initializing HashSet in Java
- Initialize HashSet in Java
- Difference between Iterator and Enumeration in Java
- Importance of HashSet in Java
- Difference Between Iterator and Enumeration Interface in Java
- Convert array to HashSet in Java

Advertisements