Convert Map to Map

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

How can I convert Map to Map ?

This does not work:

Map map = ne         


        
11条回答
  •  执笔经年
    2021-01-31 14:04

    If your Objects are containing of Strings only, then you can do it like this:

    Map map = new HashMap(); //Object is containing String
    Map newMap =new HashMap();
    for (Map.Entry entry : map.entrySet()) {
           if(entry.getValue() instanceof String){
                newMap.put(entry.getKey(), (String) entry.getValue());
              }
     }
    

    If every Objects are not String then you can replace (String) entry.getValue() into entry.getValue().toString().

提交回复
热议问题