Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Create Own HashMap in Java?

I know about hashing algorithm and hashCode() to convert "key" into an equivalent integer (using some mathematically random expression) that is then compressed and stored into buckets.

But can someone point me to an implementation or at least data structure that should be used as baseline?

I haven't found it anywhere on the web.

like image 409
Taranfx Avatar asked Jan 22 '23 11:01

Taranfx


1 Answers

Just use eclipse and use latest JDK. Source code of Java core packages come attached with the JDK. Open HashMap class and you are good to go. Some of the method implementations may come from AbstractMap, AbstractCollection etc. This is because of proper OO design. You can navigate to all the classes of JDK in your eclipse.

UPDATE: Why Eclipe ( or an IDE) instead of just opening the zip file? An IDE can be used to move back and forth between classes and in general is good for "reading" code. Note not all method implementations are in one file like HashMap.java and so simple text editors like notepad++, or textpad may not be enough. A full blown IDE like eclipse/IDEA can make it much easier. Atleast it worked for me :)

like image 178
Kannan Ekanath Avatar answered Jan 29 '23 23:01

Kannan Ekanath