首页 > 编程语言 >java8 数据分组的两种方式?

java8 数据分组的两种方式?

时间:2023-05-11 09:22:47浏览次数:42  
标签:Map 两种 false groupingBy stream 分组 true java8

第一种: 使用partitioningBy 收集器

例子:Map<Boolean, List<Art>> = artist.stream.collect(partitioningBy(x-> x.isSolo()));

根据true, false 分类,满足条件的返回到true,不满足的返回到false

第二种:使用groupingBy分组

Map<String, List<Art>> = artist.stream.collect(groupingBy(x-> x.getMainMusician()));

根据其中属性值进行分类,类似于Mysql中的 group by

标签:Map,两种,false,groupingBy,stream,分组,true,java8
From: https://www.cnblogs.com/dongfangzhaoyue/p/17390005.html

相关文章