一、前言
java8使用Stream流更改map中的value,key不变,仅修改原map中的value。
二、代码
Map> map = new HashMap<>(); map.put("java", Arrays.asList("1.7", "1.8")); Map collect = map.entrySet().stream() .collect(Collectors.toMap( stringListEntry -> stringListEntry.getKey(), stringListEntry -> new Java(stringListEntry.getValue())));
Collectors.toMap的两个参数的方法,第一个参数代表如何获取key,第二个代表如何获取value,因为key没有变,所以直接取entry的key,value的话可根据需要进行转换。



