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();
        List<Integer> collect = stream.filter(entry -> entry.getValue() > 17)
                // 遇到参数不知道怎么写的,直接new一个接口,然后快捷键提示转成lambda
                .flatMap(stringIntegerEntry -> Stream.of(stringIntegerEntry.getValue()))
                .collect(Collectors.toList());
        System.out.println(collect);


List<Integer> collect1 = stream.filter(entry -> entry.getValue() > 17)
// 遇到参数不知道怎么写的,直接new一个接口,然后快捷键提示转成lambda
.map(stringIntegerEntry -> stringIntegerEntry.getValue())
.collect(Collectors.toList());
 

 

posted @ 2023-12-10 20:40  我没有出家  阅读(62)  评论(0)    收藏  举报