Custom HashMap implementation

前端 未结 7 1869
挽巷
挽巷 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:49

    Short Answer:

    It would be an array of arrays (or Lists).

    Object[][] map;
    

    where map[bucketIndex] would return the 'bucket'.

    When inserting something you need a function to calculate bucketIndex this would use the hashcode of the inserted object.

    Boom done!

    :)

提交回复
热议问题