Convert HashMap.toString() back to HashMap in Java

后端 未结 12 1684
执念已碎
执念已碎 2020-12-14 00:35

I put a key-value pair in a Java HashMap and converted it to a String using the toString() method.

Is it possible to convert t

12条回答
  •  無奈伤痛
    2020-12-14 01:12

    This may be inefficient and indirect. But

        String mapString = "someMap.toString()";
        new HashMap<>(net.sf.json.JSONObject.fromObject(mapString));
    

    should work !!!

提交回复
热议问题