Convert Map to Map

后端 未结 11 1839
暗喜
暗喜 2021-01-31 13:27

How can I convert Map to Map ?

This does not work:

Map map = ne         


        
11条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-31 14:16

    Great solutions here, just one more option that taking into consideration handling of null values:

    Map map = new HashMap<>();
    
    Map stringifiedMap = map.entrySet().stream()
                 .filter(m -> m.getKey() != null && m.getValue() !=null)
                 .collect(Collectors.toMap(Map.Entry::getKey, e -> (String)e.getValue()));
    

提交回复
热议问题