【发布时间】:2016-02-04 18:40:57
【问题描述】:
很抱歉问这个问题,但我是 Java 新手。
Hashtable<byte[],byte[]> map = new Hashtable<byte[],byte[]>();
byte[] temp = {1, -1, 0};
map.put(temp, temp);
byte[] temp2 = {1, -1, 0};;
System.err.println(map.containsKey(temp2));
不适用于 .containsKey(因为打印结果为“假”)
Hashtable<Integer,Integer> mapint = new Hashtable<Integer, Integer>();
int i = 5;
mapint.put(i, i);
int j = 5;
System.err.println(mapint.containsKey(j));
有效(打印结果为“真”)
我知道这与对象引用有关,但搜索后无法找到任何解决方案...
无论如何我可以使用 Hashtable 来查找具有 Array 类型的键吗?我只是想测试一个特定的数组是否在 Hashtable 中作为键...
任何点击都会很棒。谢谢!!!
【问题讨论】:
-
对于您的具体问题,您可以使用
ByteBuffer、map.put(ByteBuffer.wrap(temp), temp);包装数组。