- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
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
Find minimum element of HashSet in Java
To get the minimum element of HashSet, use the Collections.min() method.
Declare the HashSet −
Set<Integer> hs = new HashSet<Integer>();
Now let us add the elements −
hs.add(29); hs.add(879); hs.add(88); hs.add(788); hs.add(456);
Let us now get the minimum element −
Object obj = Collections.min(hs);
The following is an example to find the minimum element of HashSet −
Example
import java.util.*; public class Demo { public static void main(String args[]) { // create hash set Set<Integer> hs = new HashSet<Integer>(); hs.add(29); hs.add(879); hs.add(88); hs.add(788); hs.add(456); System.out.println("Elements in set = "+hs); // finding minimum element Object obj = Collections.min(hs); System.out.println("Minimum Element = "+obj); } }
Output
Elements in set = [788, 88, 456, 29, 879] Minimum Element = 29
- Related Articles
- Find maximum element of HashSet in Java
- Remove specified element from HashSet in Java
- Find the minimum element of a Vector in Java
- Find minimum element of ArrayList with Java Collections
- Remove single element from a HashSet in Java
- Check for an element in a HashSet in Java
- Importance of HashSet in Java
- HashSet in Java
- Java Program to check if a particular element exists in HashSet
- Add element to HashSet in C#
- Get size of HashSet in Java
- Initialize HashSet in Java
- Initializing HashSet in Java
- The HashSet in Java
- Iterate through elements of HashSet in Java

Advertisements