package com.shrimpking.t3;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
/**
* Created by IntelliJ IDEA.
*
* @Author : Shrimpking
* @create 2024/9/11 16:42
*/
public class MaxMinAndCountStream
{
public static void main(String[] args)
{
List<Integer> list = Arrays.asList(5,3,1,9,2);
//
Optional<Integer> max = list.stream().max((x1,x2)-> x1.compareTo(x2));
System.out.println("流中最大的元素=" + max.get());
Optional<Integer> min = list.stream().min((y1,y2) -> y1.compareTo(y2));
System.out.println("流中最小的元素=" + min.get());
long count = list.stream().count();
System.out.println("流中元素的数目=" + count);
}
}
09-09
551
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
09-06
242
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)