can you explain how hash map works in java 8 ? with the tree implentation
Map new implementation using tree
Before java8, hashmap was implemented using linked list. If you learnt about hashmaps already, then you should be knowing of linear chains(created due to collisions), these linear chains were implemented using linked list.
Now when data set is large, these collisions increase , thus increasing time complexity of search and other operations. See increase in chain length linearly affects increase in search time complexity.
So to avoid this linear increase, after certain threshold value of chain length, java convert these chains(linked list) into binary search trees.
Binary search trees operations are logarithmic (in case you don’t know, learn about BSTs)
Logarithmic time complexities are much lesser than linear as input size increases.
Thanks
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.