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(Assume there is no such data structure called HashMap)“. The only answer I could think of was by implementing Associative Arrays (but then again, Java doesnt have associative arrays).
Could you experts please pour in your thoughts on this question?
This question was asked to me in an interview. I think the only way
Share
Short Answer:
It would be an array of arrays (or Lists).
where
map[bucketIndex]would return the ‘bucket’.When inserting something you need a function to calculate
bucketIndexthis would use thehashcodeof the inserted object.Boom done!
🙂