Get the Minimum and maximum number in an array in Java
Description
The following code shows how to get the Minimum and maximum number in an array.
Example
//from w w w .j a va2 s . c o m
import java.util.Arrays;
import java.util.Collections;
public class Main {
public static void main(String[] args) {
Integer[] numbers = { 8, 2, 6, 7, 0, 1, 4, 9, 5, 3 };
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);
}
}
The code above generates the following result.
Home »
Java Tutorial »
Java Data Type »
Java Tutorial »
Java Data Type »