对一个list中的元素进行分组,并统计各个元素出现的次数。放入map<String,Long>。
代码如下:
@Test public void test8() {List<String> items =Arrays.asList("1", "2", "3","4", "1", "3", "3");Map<String, Long> result =items.stream().collect(Collectors.groupingBy(Function.identity(), Collectors.counting()));System.out.println(result); }