【发布时间】:2013-07-18 20:57:33
【问题描述】:
我想使用HashMaps<String, V>,其中值类型V 应该是二维int 数组(int[][])。
Map<String,int[][]> map = new HashMap<>();
int[][] a = new int[][]{ {1, 2} };
map.put("test", a);
System.out.println("Test:" + map.containsKey("test")); // Test: true
System.out.println("key ==== " + map.get("test")); // Key === [[I@19a8942
我试图拥有一个访问唯一值的键,即二维数组,数组的大小是固定的array[1][3],这是恒定的。键的数量会随着时间而增长,但数组不会。例如:
Key1 -> [no1, no2, no3]
key2 -> [no4, no5, no6]
- 我想访问数组值,现在出现错误。
- 有没有更好的方法来实现这一点?理想情况下,我希望它按键排序。
我不是 Java 方面的专家,但在阅读了一些关于地图的内容后,我觉得这对我来说最合适。
【问题讨论】:
-
你得到什么错误?你做对了。
-
如果数组的第一个关键维度不会改变,为什么不使用类似 HashMap
> 的东西? -
@GonzaloNaveira。为什么要使用 HashMap 来表示值?
-
只是因为如果他不使用矩阵,我看不出使用两个数组的意义!
标签: java hashmap treemap sortedmap