Convert HashMap.toString() back to HashMap in Java

后端 未结 12 1693
执念已碎
执念已碎 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:11

    It is possible to rebuild a collection out of its string presentation but it will not work if the elements of the collection don't override their own toString method.

    Therefore it's much safer and easier to use third party library like XStream which streams objects in human readable XML.

提交回复
热议问题