首页 > 其他分享 >Stream操作双列集合

Stream操作双列集合

时间:2022-12-07 11:33:06浏览次数:34  
标签:map Stream stream Map put 双列 personHashMap 集合

双列集合:转换成单列集合后再创建

        Map<String,Integer> map = new HashMap<>();
        map.put("蜡笔小新",19);
        map.put("黑子",17);
        map.put("日向翔阳",16);

        Stream<Map.Entry<String, Integer>> stream = map.entrySet().stream();
        HashMap<String,Integer> personHashMap = new HashMap<String,Integer>();
        personHashMap.put("蜡笔小新",19);
        personHashMap.put("黑子",17);
        personHashMap.put("日向翔阳",16);
        System.out.println(personHashMap);
        Stream<Map.Entry<String, Integer>> streams = personHashMap.entrySet().stream();
        Map<String, Integer> newPersonHashMap = streams.filter(stream -> stream.getValue() > 17)
                .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
        System.out.println(newPersonHashMap);

标签:map,Stream,stream,Map,put,双列,personHashMap,集合
From: https://www.cnblogs.com/chengqiang521/p/16962596.html

相关文章