从toString转换回Object [英] Converting back from toString to Object

查看:187
本文介绍了从toString转换回Object的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法将toString转换回Java中的对象?

Is there any way to convert from toString back to the object in Java?

例如:

Map<String, String> myMap = new HashMap<String, String>();
myMap.put("value1", "test1");
myMap.put("value2", "test2");
String str = myMap.toString();

有没有办法将此String转换回地图?

Is there any way to convert this String back to the Map?

推荐答案

简答:否。

稍长答案:不使用 toString 。如果有问题的对象支持序列化,那么可以从序列化的字符串返回到内存中的对象,但这是一个完整的蜡球。了解序列化和反序列化以了解如何执行此操作。

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.

这篇关于从toString转换回Object的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆