Is there any way to convert from toString back to the object in Java?
For example:
Map myMap = new HashMap
public class CustomMap<K, V> extends HashMap<K, V>{
public String toString(){
//logic for your custom toString() implementation.
}
}
Have a class that extends HashMap and override the toString() method. Then you can do the following and achieve what you want to,
CustomMap<String, String> myMap = new CustomMap<String, String>();
myMap.put("value1", "test1");
myMap.put("value2", "test2");
String str = myMap.toString();