今天coding的时候,用到了byte[]数组作为hashmap的key值,测试的时候,发现不能够根据相同的byte[],得到相应的value值,google了一下,发现,byte[]数组作为key值,只是数组的地址的引用的hashcode,不能够根据byte[]数组的内容来,创建相应的hashcode,也就是所谓的索引key。所以,如果想用byte[]数组来作为map的key值的话,有三种方法:
1.将byte[],先转化为string,
2.将采用list<byte>
3.将byte[]自己包装,使用byte[]数组的内容来重写hashcode和euquals方法,
write up just for my own reference.
1.将byte[],先转化为string,
2.将采用list<byte>
3.将byte[]自己包装,使用byte[]数组的内容来重写hashcode和euquals方法,
write up just for my own reference.