java8 steam Map 值转化

Map<String, String> result = map.entrySet().stream()
                  .collect(Collectors.toMap(xxx));

例子:Map<String,List> 转化为 Map<String,Integer> ,其中Integer是原来list的size

Map<String, Integer> result = map.entrySet().stream()
                  .collect(Collectors.toMap(Map.Entry::getKey, entry -> entry.getValue().size())));

其他方式请参考:https://stackoverflow.com/questions/25903137/java8-hashmapx-y-to-hashmapx-z-using-stream-map-reduce-collector/25903190

    原文作者:wt_better
    原文地址: https://blog.csdn.net/wt_better/article/details/91383862
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞