Stream Collectors - summarizingInt

news/2024/7/5 8:01:13 标签: java

public static <T> Collector<T,​?,​IntSummaryStatistics> summarizingInt​(ToIntFunction<? super T> mapper)

public static <T> Collector<T,​?,​LongSummaryStatistics> summarizingLong​(ToLongFunction<? super T> mapper)

public static <T> Collector<T,​?,​DoubleSummaryStatistics> summarizingDouble​(ToDoubleFunction<? super T> mapper)

这三个方法功能类似只是针对的数据类型不一样。这里只取summarizingInt这个方法来说明。

先看例子:

void test40() {

        List<User> userList = List.of((new User("mail1","adr1",3)),(new User("mail2","a2",5)),(new User("mail2","adr3",9)),(new User("mail1","adrr4",13)));

        IntSummaryStatistics iss = userList.stream().collect(Collectors.summarizingInt(a -> a.getAge()));

        System.out.println(iss.toString());

    }

运行结果:IntSummaryStatistics{count=4, sum=30, min=3, average=7.500000, max=13}

看吧,这个方法其实就是进行简单数据统计的,从一堆数据中得出数据数量,总和,最小值,最大值,平均值。


http://www.niftyadmin.cn/n/928501.html

相关文章

1_npctele

1_npctele 其他同1_itemtele slot       排序字段(传送NPC中的显示根据这个来排序 也就是 数值越小的越在前)creature    传送员id (这里指定ID可以设置多个传送员)parentmenuidicongossipmapposition_xposition_yposition_zposition_oactionvendoridreqtypereqva…

Go语言的通道(2)-缓冲通道

有缓冲的通道相比于无缓冲通道&#xff0c;多了一个缓存的功能&#xff0c;如下图描述的一样&#xff1a; 从图上可以明显看到和无缓冲通道的区别&#xff0c;无缓冲必须两个Goroutine都进入通道才能进行数据的交换&#xff0c;这个不用&#xff0c;如果数据有&#xff0c;直接…

Stream Collectors - summingInt

public static <T> Collector<T,​?,​Integer> summingInt​(ToIntFunction<? super T> mapper) public static <T> Collector<T,​?,​Long> summingLong​(ToLongFunction<? super T> mapper) public static <T> Collector…

为什么要应用编排,应用编排能做什么?

随着服务数量的增多&#xff0c;对服务配置的管理也提出了更高的要求。如何去管理诸多服务&#xff0c;不同环境中存在差异部分以及在系统运维阶段需要灵活变更的部分&#xff0c;这些都是服务配置管理中需要解决的问题。通过应用编排产生的编排模版保存了每个服务本身具体的部…

Stream Collectors - toCollection

public static <T,​C extends Collection<T>> Collector<T,​?,​C> toCollection​(Supplier<C> collectionFactory) 简述一下就是把集合中的元素转换成参数指定的集合类型进行保存。 看个例子&#xff1a; void test42() {List<Integer> …

mysql的limit优化

我们工作中可能会遇到大数据量&#xff08;假设上千万条&#xff09;分页的情况&#xff0c;执行的语句类似以下sql语句&#xff1a; select * from record limit 2000000,10 运行这条语句&#xff0c;时间保持在30秒左右&#xff0c;这样的性能是很差的。 那我们该怎么去优化它…

Stream Collectors - toList、toSet

public static <T> Collector<T,​?,​List<T>> toList() public static <T> Collector<T,​?,​Set<T>> toSet() 上面说完了toCollection这里接着说一下toLIst和toSet这两个方法。其实这两个方法的作用toCollection都能实现&#xff…

CentOS 7 安装 Nginx

导语 下面会用 yum 和编译两种方式来安装 Nginx。 yum 安装 使用 yum 命令&#xff0c;是相对简单的&#xff0c;输入 yum install -y nginx 显示如上界面&#xff0c;既是安装成功。接下来开启 Nginx 服务 配置文件在 /etc/nginx/nginx.conf&#xff0c; 代码文件地址在 /usr…