如何将值/从NestedMap中获取值 [英] How to put/get values into/from Nested HashMap
本文介绍了如何将值/从NestedMap中获取值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
I want to create a nested HashMap that will take two keys of type float and give out value of type Integer.
我想创建一个嵌套的HashMap,它需要两个类型为float的键并给出Integer类型的值。 public static HashMap< Float,HashMap< Float,Integer>> hashX = new HashMap< Float,HashMap< Float,Integer>>();
public static HashMap<Float, HashMap<Float, Integer>> hashX = new HashMap<Float,HashMap<Float, Integer>>();
是否有一个像普通HashMap那样的简单方法来获取/获取值:
Is there a simple method of putting/getting the values like an ordinary HashMap i.e.
hashX.put(key, value);
hashX.get(key);
或者它是一个更复杂的方法吗?
我在网上搜索了一个解决方案,但是发现很难找到适用于我的解决方案。
or is it a more complicated method that must be used? I have searched around the web for a solution but am finding it tough to find a solution that applies to me. Any help would be appreciated!
推荐答案
Map<Float, Map<Float, Integer>> map = new HashMap<>();
map.put(.0F, new HashMap(){{put(.0F,0);}});
map.put(.1F, new HashMap(){{put(.1F,1);}});
map.get(.0F).get(.0F);
这篇关于如何将值/从NestedMap中获取值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文