java - Using a byte array as Map key -
Do you see any problems using a byte array as a map key? I can havehed by new string (byte [])
and string
but it is easier to use byte []
.
The problem is that byte []
is equivalent to Object identification uses
and hashode
, so that
byte [] b1 = {1, 2, 3} byte [] B2 = {1, 2, 3}
will not match in a hashm
. I see three options:
- Wrapping in a
string
, but then you have to be careful about encoding issues (you have to make sure that byte -> String -> Byte gives you the same bytes. - Use the
list & lt; byte & gt;
(can be expensive in memory). < Li>
hashode
and equal
.
Comments
Post a Comment