学习记录23

Java 8 的 Stream API
import java.util.Arrays;

public class MaxInArrayWithStream {
public static void main(String[] args) {
int[] array = {12, 45, 67, 23, 9, 55};
int max = Arrays.stream(array).max().orElseThrow(() -> new IllegalArgumentException("数组不能为空"));
System.out.println("数组中的最大值是: " + max);
}
}

posted @ 2025-02-20 19:58  吉尼泰梅  阅读(10)  评论(0)    收藏  举报