Collectors.groupingBy

5 为什么要分成两组???

	public static void main(String[] args) {
        String str = "5, 5, 1, 4, 2, 3, 6, 5, 4, 1, 3, 2, 6, 5, 1, 3, 4, 8, 2, 5, 1, 8, 2, 3, 4,5, 3, 8, 2, 1, 1, 9, 8, 2, 10, 7, 1, 5";
        List<String> list = new ArrayList<>(Arrays.asList(str.split(",")));
        System.out.println(list.toString());

        Map<String, Long> map = list.stream().collect(Collectors.groupingBy(Function.identity(), Collectors.counting()));
        System.out.println(map);
    }

	//结果
	[5,  5,  1,  4,  2,  3,  6,  5,  4,  1,  3,  2,  6,  5,  1,  3,  4,  8,  2,  5,  1,  8,  2,  3,  4, 5,  3,  8,  2,  1,  1,  9,  8,  2,  10,  7,  1,  5]
	{ 1=7,  2=6,  3=5,  4=4,  5=5, 5=2,  6=2,  7=1,  8=4,  9=1,  10=1}

不理解 5 为什么要分成两组??? 求解

还是不理解lamda表达式啊,
数据格式要求严格:" 5, 5, 1 "这个空格很有灵性啊

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值