HashMap with byte array key and String value - containsKey() function doesn't work
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.