Find maximum element of HashSet in Java
Description
The following code shows how to find maximum element of HashSet.
Example
// w w w . j a v a 2 s .co m
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
public class Main {
public static void main(String[] args) {
Set<Long> hashSet = new HashSet<Long>();
hashSet.add(new Long("1111111111"));
hashSet.add(new Long("2222222222"));
hashSet.add(new Long("3333333333"));
hashSet.add(new Long("4444444444"));
hashSet.add(new Long("5555555555"));
Object obj = Collections.max(hashSet);
System.out.println(obj);
}
}
The code above generates the following result.