import java.util.Collections;
import java.util.HashSet;
public class FindMinMax {
public static void main(String[] args) {
// TODO Auto-generated method stub
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);
Object obj2= Collections.min(hashSet);
System.out.println("Minimum Element of Java HashSet is : " + obj2);
System.out.println("Maximum Element of Java HashSet is : " + obj);
}
}
Console:
Minimum Element of Java HashSet is : 2
Maximum Element of Java HashSet is : 9