访问String的HasMap的特定元素&数组列表

时间:2015-12-05 10:15:20

标签: arraylist hashmap

我在我的项目中使用了数组double xyz [20000] [20000],但是java给出了“堆空间”错误。我打算使用Hashmaps而不是上面的数组。所以我需要使用Hashmap。 现在的问题是,与java数组一样,如果需要访问一个元素,我们可以像xyz [10] [10]一样访问它,但是如果我使用上面的Hashmap那么我如何访问一个特定的元素,如key = 10和各个阵列中的第10个元素?

1 个答案:

答案 0 :(得分:0)

HashMap始终以这种方式工作。您已在java中的HashMap类中指定了函数来获取键的值,getKey()getValue()应该为您提供相应键的键和值。

Map<int, List<Integer>> entry = new HashMap<int, List<Integer>>();
//rest of the code, putting values etc.
//the accessing data of 10th index
int key = entry.getKey();
List<Integer> values = entry.getValue();
System.out.println("Key = " + key);
System.out.println("Values = " + values.get(10) + "\n");
相关问题