package array; import java.util.Arrays; import java.util.Collections; public class getMinAndMax { public static void main(String[] args) { /** * 获取数组中的最大值和最小值 */ Integer[] number = { 21, 43, 21, 32, 1, 2, 4, -1, 93, 5467, 38 }; System.out.println(Arrays.asList(number)); int min = Collections.min(Arrays.asList(number)); int max = Collections.max(Arrays.asList(number)); System.out.println("数组的最小值是:" + min); System.out.println("数组的最大值是:" + max); } }
输出结果
[21, 43, 21, 32, 1, 2, 4, -1, 93, 5467, 38] 数组的最小值是:-1 数组的最大值是:5467