Suppose I want to create a HashSet
or a HashMap
whose keys are arrays of primitive types, like below:
Set<int[]> setOfIntArrays = new HashSet<>();
Map<char[], String> mapOfCharArrays = new HashMap<>();
What hash codes these structures will be using for the arrays?
I know that the root class Object
contains hashCode()
and it is therefore may be used for instances of any inherited class (in which it may be overridden or not). The Arrays
class has a bunch of static hashCode(...)
methods for arrays of all primitive types. Are these methods also "built-in" as (overridden) instance methods of arrays of primitive types? Since arrays act as ordinary classes in collections and maps, it seems logical to be so. However, there is no javadoc for, say, class int[]
and the "Arrays" chapter in JLS doesn't clarifies the situation either.