Is there any way to convert from toString back to the object in Java?
For example:
Map<String, String> myMap = new HashMap<String, String>();
myMap.put("value1", "test1");
myMap.put("value2", "test2");
String str = myMap.toString();
Is there any way to convert this String back to the Map?
To reverse the characters of a String object, we first need to convert it to a mutable StringBuilder object. Next, we need to call the reverse() method to reverse the character sequence of the string. Finally, we can obtain the reversed string from the StringBuilder object by calling the toString() method on it.
ToString() method. The default implementation of the ToString method returns the fully qualified name of the type of the Object, as the following example shows. Because Object is the base class of all reference types in the .
Short answer: no.
Slightly longer answer: not using toString
. If the object in question supports serialization then you can go from the serialized string back to the in-memory object, but that's a whole 'nother ball of wax. Learn about serialization and deserialization to find out how to do this.
No there isn't.
toString() is only intended for logging and debug purposes. It is not intended for serialising the stat of an Object.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With