当前位置:网站首页>流式计算知识
流式计算知识
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));
边栏推荐
- keyboard entry.
- oracle 11g rac 磁盘组有空间无法增加数据文件?
- Remote office related issues to be considered by enterprises
- Flask (VIII) - form processing
- Before applying data warehouse ODBC, you need to understand these problems first
- Day 47 how to query a table
- [TiO websocket] III. The TiO websocket server can send messages to users anywhere
- LeetCode刷题 —— 手撕二叉树
- Flask (III) -- variable rules
- ESP8266_ Connect to Alibaba cloud through mqtt protocol
猜你喜欢

一万字彻底学会堆和二叉树

ESP8266_SmartConfig

Openstack explanation (24) -- registration of neutron service

【ROS】noedic-moveit安装与UR5模型导入

Modularnotfounderror: no module named 'find_ version’

The ins-30131 installer failed to verify the required initial settings
![[ROS] noedic moveit installation and UR5 model import](/img/bc/865c752021a4ee68e963c09f5f632d.png)
[ROS] noedic moveit installation and UR5 model import

我们是如何连上WiFi的?

考研数学 【数列极限证明题】题型方法总结

Openstack explanation (22) -- neutron plug-in configuration
随机推荐
Opencv image basic operation (IV) -- image feature extraction (corner detection)
「INS-30131」 安装程序验证所需的初始设置失败
Runtimeerror: blobreader error:the version of imported blob doesn't match graph_ transformer
Fabric.js 动态设置字号大小
Flask (VI) - template
【Objective-C】‘NSAutoreleasePool‘ is unavailable: not available in automatic reference counting mode
MSF SMB based information collection
考研數學 【數列極限證明題】題型方法總結
Product list display
js中关键字this的理解
Identifier keyword literal data type base conversion character encoding variable data type explanation operator
Résumé de la méthode d'examen des mathématiques
Analysis of high frequency interview questions in massive data processing
Method (common method), method execution memory analysis, method overloading mechanism, method recursion
Error [error] input tesnor exceeded available data range [neuralnetwork (3)] [error] input tensor '0' (0)
Image quality evaluation including Matlab source code
[ROS] noedic moveit installation and UR5 model import
Opencv oak-d-w wide angle camera test
Package details
Thread theory