Find Minimum element of HashSet in Java

Description

The following code shows how to find Minimum element of HashSet.

Example


/*from  w  ww  .  j a va  2 s  . c o  m*/
import java.util.Collections;
import java.util.HashSet;

public class Main {
  public static void main(String[] args) {
    HashSet<Long> hashSet = new HashSet<Long>();

    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.min(hashSet);
    System.out.println("Minimum Element of Java HashSet is : " + obj);
  }
}

The code above generates the following result.





















Home »
  Java Tutorial »
    Java Collection »




Java ArrayList
Java Collection
Java Comparable
Java Comparator
Java HashMap
Java HashSet
Java Iterator
Java LinkedHashMap
Java LinkedHashSet
Java LinkedList
Java List
Java ListIterator
Java Map
Queue
Java Set
Stack
Java TreeMap
TreeSet