internal working of hashmap | hashmap internal working in java | hashmap in java | hashmap working

preview_player
Показать описание
GIT Repository URL

References

internal working of hashmap | hashmap internal working in java | hashmap in java | hashmap working

#java #hashmap #working

Download the source code from GIT
Please download the source code from below GIT repository URL :
Click on Code Drop-down → Click on Download ZIP → Open eclipse IDE
Goto File → Import → Existing projects into workspace → Next → click on checkbox
(select archive file) → click on Browse → choose the downloaded HashMapProject
ZIP file.
OR
Type the below command in git bash
Goto File → Import → Existing projects into workspace → Next → click on checkbox
(select archive file) → click on Browse → choose the downloaded HashMapProject
ZIP file.

working of HashMap.
How does put(Object, Object) method works internally.
What is Load Factor ?
What is Hash Collision ?
How does get(Object) method works internally.
Usage of equals(Object) and hashCode() in HashMap.
Usage of compareTo(Object) method in HashMap.
Java 1.8 Enhancement with respect to HashMap.

Internal working of HashMap
JVM creates 16 entries ( buckets ) in the heap memory
HashMap stores the data in the form of,
{“Key”:”Value”} pair and algorithm works only based on Key.

Whenever we use a custom object as a Key to HashMap,
then, we have to override equals(Object), hashcode and compareTo(Object) methods in custom class.
when we are using a custom class as a KEY to HashMap, HashSet or Hashtable

Whenever we use a custom object as a Value to HashMap,
then, it is NOT mandatory to override equals(Object), hashcode and compareTo(Object) methods in custom class.

Load Factor
If HashMap reaches more
than 75% of it’s capacity,
then it doubles the
existing capacity.

What is Load Factor ?
Load Factor = Threshold
Load Factor = 75% or 0.75

Working of compareTo(Object) method
● CompareTo(-) method is used, when we are putting huge number
of similar entries (elements) to the HashMap.
● It is used to compare the objects and arrange them in proper order
based on binary tree data structure.
● Binary tree data structure is implemented in Java 1.8
● By overriding the compareTo(Object) method, we can get the best
performance from HashMap
● It is recommended to override compareTo(Object) method in every
class, that is using as a key to HashMap.
Java 1.8 Enhancement to HashMap

Thank you
Рекомендации по теме
welcome to shbcf.ru