Java array find the max and min value via Collections.min/max

Description

Java array find the max and min value via Collections.min/max

import java.util.Arrays;
import java.util.Collections;

public class Main {
  public static void main(String[] args) {
    Integer[] numbers = { 1238, 3212, 1236, 7321, 3450, 1345, 3454, 9, 5435, 1233 };

    System.out.println(Arrays.toString(numbers));
    //from  ww w  .  ja v a2 s. com
    int min = (int) Collections.min(Arrays.asList(numbers));
    int max = (int) Collections.max(Arrays.asList(numbers));

    System.out.println("Min number: " + min);
    System.out.println("Max number: " + max);
  }
}



PreviousNext

Related