Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference in hash map in java 7 and 8

Tags:

java

hashmap

What is the difference in Hash Map of Java 7 and Java 8 when both works on constant complexity algorithm? As per my understanding hash map searches in constant time by generating a hash key for an object through hash function.

like image 760
John.M Avatar asked Mar 09 '16 17:03

John.M


1 Answers

In Java 7 after calculating hash from hash function if more then one element has same hash than they are searched by linear search so it's complexity is (n). In Java 8 that search is performed by binary search so the complexity will become log(n). So, this concept is wrong that hash map searches an object in constant complexity because it is not the case at all times.

like image 146
MDaniyal Avatar answered Sep 30 '22 15:09

MDaniyal