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 this String representation back to a HashMap object and retrieve the value with its corresponding key?
Thanks
解决方案
Once you convert HashMap to String using toString(); It's not that you can convert back it to Hashmap from that String, Its just its String representation.
You can either pass the reference to HashMap to method or you can serialize it
Here is the description for toString() toString()
Here is the sample code with explanation for Serialization.
and to pass hashMap to method as arg.
public void sayHello(Map m){
}
//calling block
Map hm = new HashMap();
sayHello(hm);