Convert HashMap.toString() back to HashMap in Java

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

    i converted HashMap into an String using toString() method and pass to the another method that take an String and convert this String into HashMap object

    This is a very, very bad way to pass around a HashMap.

    It can theoretically work, but there's just way too much that can go wrong (and it will perform very badly). Obviously, in your case something does go wrong. We can't say what without seeing your code.

    But a much better solution would be to change that "another method" so that it just takes a HashMap as parameter rather than a String representation of one.

提交回复
热议问题