当前位置:网站首页>流式计算知识
流式计算知识
2022-06-11 09:28:00 【java后端指南】
对象属性为数组,根据属性分组统计
数据结构:
[
{
"id":"1","name":["aa","bb"]},
{
"id":"1","name":["bb","cc"]}
]
需求:我们需要将name里面的属性值进行分组统计个数
方法一:
ArrayList<Person> peoples = new ArrayList<>();
peoples.add(new Person("1", Stream.of("aa", "bb").collect(Collectors.toList())));
peoples.add(new Person("2", Stream.of("bb", "cc").collect(Collectors.toList())));
Map<String, Integer> collect = peoples.stream().flatMap(people -> people.getName().stream()).collect(Collectors.toMap(k -> k, v -> 1, Integer::sum));
System.out.println(collect);
方法二:
HashMap<String, Integer> map = new HashMap<>();
ArrayList<Person> peoples = new ArrayList<>();
peoples.add(new Person("1", Stream.of("aa", "bb").collect(Collectors.toList())));
peoples.add(new Person("2", Stream.of("bb", "cc").collect(Collectors.toList())));
peoples.stream().flatMap(people -> people.getName().stream()).forEach(str -> map.merge(str, 1, Integer::sum));
map.forEach((k, v) -> System.out.println(k + " " + v));
边栏推荐
猜你喜欢

ESP8266_通过MQTT协议连接阿里云

MSF adds back door to normal program

Opencv oak-d-w wide angle camera test

面试常问:rem布局,flex布局等

【Objective-C】‘NSAutoreleasePool‘ is unavailable: not available in automatic reference counting mode

How do online app stores of laundry chain stores do?

Exclusive interview - dialogue on open source Zhai Jia: excellent open source projects should be seen by more people. I am honored to participate in them

Concurrent programming

ESP8266_SmartConfig

Oracle 11g RAC disk group has space and cannot add data files?
随机推荐
Detailed explanation of this and static
[ROS] noedic moveit installation and UR5 model import
Suffix Array
LeetCode刷题 —— 手撕二叉树
Tap and longtap encapsulation of touch events -- from Ono
Sword finger offer II 041 Average value of sliding window
【Objective-C】动态创建控件
Sed explanation of shell script (SED command, sed -e, sed s/ new / old /...)
affair
js中的事件
考研数学 【数列极限证明题】题型方法总结
整型提升例题
Slice of go language foundation
Ora-00059 exceeds DB_ Files limit
Openstack explanation (21) -- installation and configuration of neutron components
【Objective-C】‘NSAutoreleasePool‘ is unavailable: not available in automatic reference counting mode
Day41 process pool and thread pool
我们是如何连上WiFi的?
P4147 "jade toad Palace"
Shandong University project training (IV) -- wechat applet scans web QR code to realize web login