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:

  1. 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.
  2. Use the list & lt; byte & gt; (can be expensive in memory).
  3. < Li> hashode and equal .
to use the contents of the byte array

Comments

Popular posts from this blog

c++ - Linux and clipboard -

Visual Studio 2005: How to speed up builds when a VSMDI is open? -

booting ubuntu from usb using virtualbox -