Find Minimum element of HashSet - Java Collection Framework

Java examples for Collection Framework:HashSet

Description

Find Minimum element of HashSet

Demo Code


 
import java.util.HashSet;
import java.util.Collections;
 
public class Main {
 
  public static void main(String[] args) {
   //  w  w  w.j a v  a 2 s  . com
    //create a HashSet object
    HashSet hashSet = new HashSet();
   
    //Add elements to HashSet
    hashSet.add(new Long("91111111111111111111"));
    hashSet.add(new Long("4"));
    hashSet.add(new Long("2"));
    hashSet.add(new Long("2"));
    hashSet.add(new Long("3"));
   
    Object obj = Collections.min(hashSet);
   
    System.out.println("Minimum Element of Java HashSet is : " + obj);
  }
}

Related Tutorials