您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

Java8:HashMap 到HashMap 使用Stream / Map-Reduce / Collector

Java8:HashMap 到HashMap 使用Stream / Map-Reduce / Collector

Map<String, String> x;
Map<String, Integer> y =
    x.entrySet().stream()
        .collect(Collectors.toMap(
            e -> e.getKey(),
            e -> Integer.parseInt(e.getValue())
        ));

它不如列表代码那么好。您不能Map.Entrymap()通话中构造new ,因此工作会混入collect()通话中。

java 2022/1/1 18:15:01 有382人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶