How to convert Map to Map ? (option : using guava)

前端 未结 6 864
礼貌的吻别
礼貌的吻别 2020-12-10 01:16

I have a Map the String key is nothing but numeric value like \"123\" etc. I\'m getting numeric value because this values are

6条回答
  •  离开以前
    2020-12-10 01:48

    Here's an updated version of one of the answers below to make the resulting Map unmodifiable (no, it's not using Guava, just plain Java 8):

      import static java.util.stream.Collectors.collectingAndThen;
      import static java.util.stream.Collectors.toMap;
    
      ...
    
      newMap = oldMap.entrySet().stream().collect(collectingAndThen(
                  toMap((Map.Entry entry) -> transformKey(entry.getKey()),
                        (Map.Entry entry) -> transformValue(entry.getValue())),
                  Collections::unmodifiableMap)));
    

提交回复
热议问题