我们如何从 Java 中的 Hashmap 中获取内部值?
我在 Eclipse 中有一个哈希映射条目,如下所示:
I无法使用 key =“value” 获取值。 我收到的错误如下: java.lang.ClassCastException:类java.lang.Double无法转换为类java.util.Map(java.lang.Double和java.util.Map位于加载程序'bootstrap'的模块java.base中)
我使用的代码我试图获取如下:
Map
billed_amount_value = (Map
我无法使用 key =“value” 获取值。有人可以帮我获取正确的代码吗?
I have got a Hashmap entry in Eclipse as below:
Link to the picture of the hashmap output
I'm unable to fetch the value using the key = "value".
Error that I'm receiving is as:
java.lang.ClassCastException: class java.lang.Double cannot be cast to class java.util.Map (java.lang.Double and java.util.Map are in module java.base of loader 'bootstrap')
Code with which I'm trying to fetch is as below:
Map<Object, Double> billed_amount_value = new HashMap<Object, Double>();
billed_amount_value = (Map<Object, Double>) billed_amount.get("value");
I'm unable to fetch the value using the key = "value". Can someone please help me to get the right code?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的
hashmap
键类型是 Object,而该键的值是 Double。一旦你使用返回的值为Double(它返回key =“value”的值)。
之后,您尝试将返回值(Double 类型)转换为 Map 类型。
你想做什么?取回他的键等于“值”的值?
Your
hashmap
key type is Object while the value for that key is Double. Once you useThe returned value is Double (it returns the value of the key = "value").
After that you try to cast the return value (Double type) into Map type.
What are you trying to do? Get back the value of which his key equals "value"?