【发布时间】:2012-07-27 18:38:55
【问题描述】:
我有一个字符串变量。我需要将此变量类型转换为映射变量。例如:
String stringVariable = "apple"
// type cast this to map (Map<string,string>) stringVariable
我想将apple 用作地图而不是字符串。有可能吗?
【问题讨论】:
-
Map实现了键/值对机制。您不能直接将String类型转换为Map。声明一个Map并使用mapObj.put("key", "value")方法将字符串存储到其中。