I\'m using a HashMap: byte[] key and String value. But I realize that even I put the same object (same byte array and same string value) by using
myList.put(
A byte[]
(or any array) can't work properly as a key in a HashMap
, since arrays don't override equals
, so two arrays will be considered equal only if they refer to the same object.
You'll have to wrap your byte[]
in some custom class that overrides hashCode
and equals
, and use that custom class as the key to your HashMap.