Java Set find the Max/Min value

Description

Java Set find the Max/Min value

import java.util.Collections;
import java.util.HashSet;

public class Main {

  public static void main(String[] args) {
    HashSet<Integer> hashSet = new HashSet<>();
    hashSet.add(1);/*from ww w . j  a va 2s  . c o m*/
    hashSet.add(2);
    hashSet.add(3);
    hashSet.add(4);
    hashSet.add(5);

    Integer obj = Collections.max(hashSet);
    System.out.println(obj);
    
    obj = Collections.min(hashSet);
    System.out.println(obj);
  }
}



PreviousNext

Related