Java reduces the collection of strings to the mapping that occurs
•
Java
Treat list as Id1_ f,id2_ d,id3_ f,id1_ g. How do I use streams to obtain simplified mappings of statistics in the format < string, integer >
id1 2 id2 1 id3 1
Note: the key is_ It was part of the Can reduced functionality help?
Solution
This will complete the work:
Map<String,Long> map = Stream.of("id1_f","id2_d","id3_f","id1_g") .collect( Collectors.groupingBy(v -> v.split("_")[0],Collectors.counting()) );
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码