Custom HashMap implementation

前端 未结 7 1858
挽巷
挽巷 2021-02-06 06:45

This question was asked to me in an interview. I think the only way to get best solution is SOF. So the question was \"How would you implement a custom HashMap in java(A

7条回答
  •  余生分开走
    2021-02-06 06:51

    You should use one dimensional array. Object[] arr.

    The index of the array is the normalized hashcode from the Key object. The array holds the Pair.

    The reason the value consists of both Key and Value is that if there is any hash collision , it has to go thru the list of keys inside the slot and find out which is the correct key (using equals on the key object).

提交回复
热议问题