Stream操作双列集合

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

        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);

posted @ 2022-12-07 11:29  成强  阅读(84)  评论(0编辑  收藏  举报