Saturday 12 August 2017

Hash

HashMap works on the principle of Hashing.
hashCode() function  which returns an integer value is the Hash function. The important point to note that ,  this method is present in Object class.  


how hash  map works in java










HashMap get(Key k) method calls hashCode method on the key object.
If key is null , then Null keys always map to hash 0, thus index 0.

HashMap is non synchronized and not thread safe.On the other hand, HashTable is thread safe and synchronized.
When to use HashMap ?  answer is if your application do not require any multi-threading task, in other words hashmap is better for non-threading applications. HashTable should be used in multithreading applications. 

   

No comments:

Post a Comment