Find maximum element of HashSet - Java Collection Framework

Java examples for Collection Framework:HashSet

Description

Find maximum 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  a2 s .  c o m*/
    HashSet hashSet = new HashSet();
   
    hashSet.add(new Long("9"));
    hashSet.add(new Long("4"));
    hashSet.add(new Long("2"));
    hashSet.add(new Long("2"));
    hashSet.add(new Long("3"));
    Object obj = Collections.max(hashSet);
   
    System.out.println("Maximum Element of Java HashSet is : " + obj);
  }
}

Result


Related Tutorials