Java instances - array for maximum and minimum
The following example demonstrates how Collection.max Collection class () and Collection.min () method to find the maximum and minimum values in the array:
/* author by w3cschool.cc 文件名:Main.java */ import java.util.Arrays; import java.util.Collections; public class Main { public static void main(String[] args) { Integer[] numbers = { 8, 2, 7, 1, 4, 9, 5}; int min = (int) Collections.min(Arrays.asList(numbers)); int max = (int) Collections.max(Arrays.asList(numbers)); System.out.println("最小值: " + min); System.out.println("最大值: " + max); } }
The above code is run output is:
最小值: 1 最大值: 9