我有一个下面的 haspmap
private static Map<Integer, int[]> hm = new HashMap<Integer, int[]>();
m.put(1, new int[]{1,2,3,4,5});
hm.put(96, new int[]{23,24,2,34,22});
hm.put(101, new int[]{123,11,22,34,5,4,7});
hm.put(96, new int[]{88,87,85,80,9,7,2,1});
hm.put(96, new int[]{110,123,11,22,34,33,29,4});
我想获得 key 96 的所有值,
if (hm.containsKey(route_ID)){ ... }
然后我想迭代这些值。
最佳答案
数组是可迭代的,因此您可以使用 for (value : array)
语法对它们进行迭代。
for (int value : hm.get(96)) {
// ...
}
Map
或 HashMap
中没有内置任何东西来支持诸如 containsValue(int[])
之类的东西,但是你自己很容易实现.
关于java - 如何在 int[] 的 HashMap 中获取特定键的所有值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23234545/