Тёмный

Hashmap in Java | Internal Working of Hashmap in Java | Hashmap Implementation | DSA-One Course #30 

Anuj Bhaiya
Подписаться 499 тыс.
Просмотров 187 тыс.
50% 1

Hi guys, In this video, we're going to learn how HashMap works internally.
🥳 Join our Telegram Community:
Telegram channel: telegram.me/re...
Telegram group: telegram.me/ds...
🚀 Follow me on:
Instagram: / anuj.kumar.sharma
Linkedin: / sharma-kumar-anuj
Twitter: / realanujbhaiya
💸 Use coupon code ANUJBHAIYA on GeeksforGeeks to avail discounts on courses!
📚 Complete DSA Playlist: • DSA-One Course - The C...
Complete Android Development Playlist: • Android Development Tu...
Hashtags:
#anujbhaiya #dsaone
Tags:
hashmap in java
internal working of hashmap in java
hashmap internal implementation in java
how hashmap works internally in java
hashmap
hashmap java 8
internal working of hashmap
hashmap java
map in java
hashmap internal working in java
hashmap internal working
anuj bhaiya
hash map
hashing in java
java hashmap
hashmap implementation
working of hashmap
hashmap working
what is hashmap
internal implementation of hashmap
hash map in java
hashmaps in java
maps in java
hashmaps
hashmap in java in hindi
hashing
design hashmap
hashing in data structure
hash maps
internal working of collections in java
hashmap anuj bhaiya
mapping in java
hash map java
java 8
hash map internal working
hashmap in java apna college
what is hashmap in java
hashmap implementation in java
hashtable in java
java map
map java
internal working of hashset
map interface in java
hashing java
hashmap in c++
how hashmap works
hashmap interview questions
hash table in java
implement hashmap
java
what is hash map
anuj bhaiya java
dsa
hashset in java
hash map in c++
hashing in c++
hashset internal implementation in java
hash table in data structure
how hashmap works internally
java 8 features
hashmap c++
hashmap vs hashtable
implementation of hashmap
hash table
hashmap working in java
hashmaps java
internal working of hashmap in java in hindi
internal working of hashset in java
maps java
what is a hashmap

Опубликовано:

 

5 окт 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 209   
@amitanand3672
@amitanand3672 3 года назад
Few other questions I have come across which everyone should prepare beforehand: 1. What is bucketing in hashmap ? 2. What is loadfactor ? 3. Why hashmap is not recommended in a multi threaded environment ? 4. Implement a hashmap using custom class as key 5. is it mandatary to override equals and hashcode method ? What will happen if not overridden ? 6. What is the difference between hashmap and concurrent hashmap also explain the working of concurrent hashmap .
@mohammadfaizanhashmi4213
@mohammadfaizanhashmi4213 3 года назад
thanx a lot bro, bohot bohot shukriya bhaijan,,,maine noten kr lia hai
@frankfernandes718
@frankfernandes718 2 года назад
woh jo table tha red me 9:57 woh bucket hai
@pankajchaudhari2413
@pankajchaudhari2413 2 года назад
Bucketing is nothing but index of that node Array Hashmap doesn't contain synchronized method or variable , that's y it is not thread safe, overcome to resolve this problem we are having HashTable (as it contains all synchronized method)
@Basukinathkr
@Basukinathkr 2 года назад
Great Amit. For people who are looking here for the answers - Buckets are basically the area that contains values. Loadfactor is the threshold for the percentage of the bucket when it is decided that now bucket is going to be full and then the capacity is doubled. By default, loadfactor is 75% and capacity is 16. Totally configurable via constructor. The reason a hashmap isn't recommended in a MT env because when multiple threads start to access the data while some thread is updating it, there can be issues. Whenever overriding equals, it is mandatory to override hashCode so that every time when equals is called, the values generated by hashCode remain consistent. Rest 4 and 6 are explanatory. Can be looked on internet. Easy stuff.
@codeerBro
@codeerBro Год назад
Bucketing in HashMap is the process of storing multiple values in a single location (bucket) of the internal array of the HashMap, which is indexed using a hash function. The hash function calculates the hash code of the key and uses it as an index in the array. If multiple keys have the same hash code, they are stored in the same bucket as linked nodes. Load factor is a measure of how full a HashMap is allowed to get before its capacity is automatically increased. It is a float value that ranges from 0.0 to 1.0. When the number of entries in the HashMap exceeds the load factor multiplied by the current capacity, the capacity is increased, and the entries are rehashed. HashMap is not recommended in a multi-threaded environment because it is not thread-safe. If multiple threads access a HashMap concurrently, it may result in an inconsistent state of the HashMap, leading to data loss or unexpected results. ConcurrentHashMap is recommended for use in a multi-threaded environment. Here's an example implementation of a HashMap using a custom class as a key: class Person { private String name; private int age; public Person(String name, int age) { this.name = name; this.age = age; } // getters and setters @Override public int hashCode() { return Objects.hash(name, age); } @Override public boolean equals(Object o) { if (this == o) return true; if (!(o instanceof Person)) return false; Person person = (Person) o; return age == person.age && Objects.equals(name, person.name); } } class CustomHashMap { private List[] buckets; private int capacity; private int size; private static class Entry { K key; V value; public Entry(K key, V value) { this.key = key; this.value = value; } // getters and setters } public CustomHashMap(int capacity) { this.buckets = new List[capacity]; this.capacity = capacity; this.size = 0; } public void put(K key, V value) { int index = key.hashCode() % capacity; if (buckets[index] == null) { buckets[index] = new LinkedList(); } for (Entry entry : buckets[index]) { if (entry.key.equals(key)) { entry.value = value; return; } } buckets[index].add(new Entry(key, value)); size++; } public V get(K key) { int index = key.hashCode() % capacity; if (buckets[index] == null) { return null; } for (Entry entry : buckets[index]) { if (entry.key.equals(key)) { return entry.value; } } return null; } public int size() { return size; } // other methods } It is highly recommended to override the equals() and hashCode() methods when using custom objects as keys in a HashMap. If these methods are not overridden, the default implementations in the Object class are used, which compares object references rather than object contents. This can lead to unexpected behavior, where two objects that are considered equal by their contents are not considered equal by the HashMap. As a result, the HashMap may not be able to retrieve the values correctly.
@tech_wizard9315
@tech_wizard9315 3 года назад
Please add questions for every video of DSA course which would be enough to crack tech giant's for beginners
@DensonGeorge18
@DensonGeorge18 2 года назад
I am not a beginner. I still find the DSA 1 series very helpful to revise the concepts and learn new things for interviews.
@anujpotdar3529
@anujpotdar3529 2 года назад
I was asked this yesterday, could not answer. I started searching for solutions, most of them were too long and difficult to understand. This one taught the concept very well, keep such awesome videos, and more power to you Anuj!
@AnujBhaiya
@AnujBhaiya 2 года назад
Thanks Anuj ♥️
@codeerBro
@codeerBro Год назад
Bucketing in HashMap is the process of storing multiple values in a single location (bucket) of the internal array of the HashMap, which is indexed using a hash function. The hash function calculates the hash code of the key and uses it as an index in the array. If multiple keys have the same hash code, they are stored in the same bucket as linked nodes. Load factor is a measure of how full a HashMap is allowed to get before its capacity is automatically increased. It is a float value that ranges from 0.0 to 1.0. When the number of entries in the HashMap exceeds the load factor multiplied by the current capacity, the capacity is increased, and the entries are rehashed. HashMap is not recommended in a multi-threaded environment because it is not thread-safe. If multiple threads access a HashMap concurrently, it may result in an inconsistent state of the HashMap, leading to data loss or unexpected results. ConcurrentHashMap is recommended for use in a multi-threaded environment. Here's an example implementation of a HashMap using a custom class as a key: class Person { private String name; private int age; public Person(String name, int age) { this.name = name; this.age = age; } // getters and setters @Override public int hashCode() { return Objects.hash(name, age); } @Override public boolean equals(Object o) { if (this == o) return true; if (!(o instanceof Person)) return false; Person person = (Person) o; return age == person.age && Objects.equals(name, person.name); } } class CustomHashMap { private List[] buckets; private int capacity; private int size; private static class Entry { K key; V value; public Entry(K key, V value) { this.key = key; this.value = value; } // getters and setters } public CustomHashMap(int capacity) { this.buckets = new List[capacity]; this.capacity = capacity; this.size = 0; } public void put(K key, V value) { int index = key.hashCode() % capacity; if (buckets[index] == null) { buckets[index] = new LinkedList(); } for (Entry entry : buckets[index]) { if (entry.key.equals(key)) { entry.value = value; return; } } buckets[index].add(new Entry(key, value)); size++; } public V get(K key) { int index = key.hashCode() % capacity; if (buckets[index] == null) { return null; } for (Entry entry : buckets[index]) { if (entry.key.equals(key)) { return entry.value; } } return null; } public int size() { return size; } // other methods } It is highly recommended to override the equals() and hashCode() methods when using custom objects as keys in a HashMap. If these methods are not overridden, the default implementations in the Object class are used, which compares object references rather than object contents. This can lead to unexpected behavior, where two objects that are considered equal by their contents are not considered equal by the HashMap. As a result, the HashMap may not be able to retrieve the values correctly.
@tanmoydutta5846
@tanmoydutta5846 2 года назад
I was also asked the internal implementation of this in JPMC interview (technical round).
@shivisharma4267
@shivisharma4267 3 года назад
Bhaiya please make a video on roadmap to cloud computing🙏🙏🙏
@GuruPrasadShukla
@GuruPrasadShukla 2 года назад
best video on hashmaps in whole coder community!
@tsp57
@tsp57 Месяц назад
Beautifully exlpained!
@chetantailor3620
@chetantailor3620 3 года назад
Another worth 16 minutes 👌💫
@Vishal-242
@Vishal-242 3 года назад
Most clear explanation I have seen
@nandabawane9117
@nandabawane9117 3 года назад
No wondor.... Your Videos are always be useful...
@madhusmitamishra7801
@madhusmitamishra7801 3 года назад
Watched this before 15mins of my interview and interviewer asked the same question. Thank you ☺️.
@awwush
@awwush 3 года назад
are Abhi aapka hi videos dekhra tha ARRAYS superb!!
@sandeshtiwaris6829
@sandeshtiwaris6829 2 года назад
Yes, it was helpful
@surajdhotre2889
@surajdhotre2889 3 года назад
U really gr8 bhaiya.Your video hleping me a lots....god bless u 😇
@antorsaha6065
@antorsaha6065 2 года назад
Thank you bhaiya for this series. This is most useful dsa series.😍
@AnujBhaiya
@AnujBhaiya 2 года назад
You're welcome ☺️
@adityadev2825
@adityadev2825 3 года назад
Yes the videos was very helpful
@8750795655
@8750795655 2 года назад
Great, very well and easily explained
@PAWANKUMAR-el2zk
@PAWANKUMAR-el2zk 3 года назад
Bhaiya make more such kind of videos on all collection's or tree👍🏻
@factsEcho--
@factsEcho-- 3 года назад
Yes video was helpful 🙂🙂
@AjayKumar-tl1qy
@AjayKumar-tl1qy 2 года назад
Calculating hash and index number are two different things while putting value in the hash map. for index calculation hash map uses (n-1) & hash where n is bucket length. its never uses hash as index number.
@sachingl4266
@sachingl4266 2 года назад
Thanks
@itz_me_imraan02
@itz_me_imraan02 3 года назад
The videos are too gud... Plz try to maintain consistency in DSA course🙏🙏...
@richasharma6361
@richasharma6361 3 года назад
Hello bhaiya, bhaiya bug bounting ke uper video bhi banye with practical knowledge
@itsShashwat
@itsShashwat 3 года назад
Great video @Anuj Bhaiya
@gauravkhare1836
@gauravkhare1836 Месяц назад
Yes, it is very helpful
@vivekshokeen1192
@vivekshokeen1192 2 года назад
YES, IT WAS HELPFUL! bhaiya
@codehustler8582
@codehustler8582 2 года назад
YES IT HELPS
@av98
@av98 7 месяцев назад
Helpful
@thebugger7269
@thebugger7269 11 месяцев назад
Sir please make a video on hash mam and concurrent hash map how perform different internally
@piyushkesharwani1987
@piyushkesharwani1987 3 года назад
Great one, Please make a video on the Internal working of "HEAP" also.
@keshav19_20
@keshav19_20 3 года назад
Nice bhaiya Bhaiya linked list kb se chalu ho gi??
@auroshisray9140
@auroshisray9140 2 года назад
thanks bhaiya!
@pareeks
@pareeks 2 года назад
Great video. Two things TBC: 1. New values are pre-appended, not appended at end. 2. In case of collision in get(Key), value is not checked for equals() but key is checked.
@fvdf-y6v
@fvdf-y6v 8 месяцев назад
YES, IT WAS HELPFUL
@venkatasaikrishnamarri1158
@venkatasaikrishnamarri1158 2 года назад
perfect tutorial
@shashwatmishra7056
@shashwatmishra7056 11 месяцев назад
A guy from Amazon Seattle, Washington, interviewed me today asked me the same concept
@rajanwalia4tech
@rajanwalia4tech 3 года назад
I didn't knew about that java8 implement hashmap using self balancing BST. Yes video was helpful.
@shashwatsharma9904
@shashwatsharma9904 3 года назад
next video pls make on working of hashset
@ShankarKumar-ko8lt
@ShankarKumar-ko8lt 2 года назад
This video is very Helpful for me Thank you Anuj Bhaiya.
@surajchavan1000
@surajchavan1000 Год назад
Yes, very helpful
@mousumi721
@mousumi721 3 года назад
Thank you bhaiya for this series🌸.i'm really grateful.
@agyaani8060
@agyaani8060 3 года назад
Thankuu so much bhaiya❤❤
@mruduladdipalli5417
@mruduladdipalli5417 2 года назад
EK Number Bhai
@rameezkhan2220
@rameezkhan2220 2 года назад
The way of explanation is excellent👌👌👌
@nitin5865
@nitin5865 3 года назад
Perfectly explained 👍
@surajwaghmare4653
@surajwaghmare4653 Год назад
Very Helpful
@ankitdubey6813
@ankitdubey6813 3 года назад
This series is the most useful ❤
@raghavendraraviteja1055
@raghavendraraviteja1055 Год назад
Thanks, it is helpful
@swati0909
@swati0909 Месяц назад
Awesome 👍
@Grandmaster-e7s
@Grandmaster-e7s 2 месяца назад
yes it was helpful
@gurkiratkaur4087
@gurkiratkaur4087 5 месяцев назад
Very helpful
@kashisharora1018
@kashisharora1018 2 года назад
Very nice explanation
@anupamdubey5736
@anupamdubey5736 3 года назад
😯😯Where's that CAP/BEANIE! Loved the explanation!!❤❤
@rahulshinde6648
@rahulshinde6648 Год назад
Thank you
@Naveenkumar-qs1qd
@Naveenkumar-qs1qd 22 дня назад
sandar jabardast jinda baad
@meetsoni1938
@meetsoni1938 2 года назад
Yes it is helpful 😃
@unboxingsillystuffs4920
@unboxingsillystuffs4920 2 года назад
Thank you Anuj..you explained very well.
@kalpeshsaubhri
@kalpeshsaubhri Год назад
Bhai end me jo BST wala concept btaya usse maja aa gya.
@shivambaghel9668
@shivambaghel9668 2 года назад
Is the concept of re -hashing in hashmap is converting the linked list into self balancing tree (what you taught at the end)
@devendersinghrathore8837
@devendersinghrathore8837 2 года назад
Yes. It is really helpful.
@vishaldas5692
@vishaldas5692 3 года назад
Yes it was helpful btw plzz make a video on how to convert that linked list into bst in hashed map as u said is done in Java 8..🙃❣️
@AdityaKumar-ic8wz
@AdityaKumar-ic8wz 3 года назад
Make a video for beginners On how to become a free lancer
@harrygaming8719
@harrygaming8719 2 года назад
Yes
@StudyiMnimal1743
@StudyiMnimal1743 3 года назад
great bhaiya
@shubhammahawar6206
@shubhammahawar6206 2 года назад
Thanks for explaining.
@ritikarai1232
@ritikarai1232 3 года назад
Yes it was helpful😁
@jiteshjs99
@jiteshjs99 Месяц назад
Great explanation :)
@ashwithchandra2622
@ashwithchandra2622 2 года назад
thanks bhayya nice explanation😘
@are_amay
@are_amay 3 года назад
maza aa gaya bhai
@dharmeshkhasiya6737
@dharmeshkhasiya6737 2 года назад
Thanks for explaining
@tejasbavkar2811
@tejasbavkar2811 2 года назад
thank you..
@chaitanyaasati
@chaitanyaasati 3 года назад
Yeah, It helped to understand the concept.
@sumeet115
@sumeet115 Год назад
Great explanation. Thanks 👍 ..
@stith_pragya
@stith_pragya Год назад
Thank You So Much bhaiya,............🙏🙏🙏
@naro.tam_
@naro.tam_ 3 года назад
i did it by myself
@aishapi6320
@aishapi6320 7 месяцев назад
Awesome content and presentation
@nileshmutthe5457
@nileshmutthe5457 2 года назад
This was helpful
@ZSHADOW18
@ZSHADOW18 3 года назад
16:24 the video was not helpful but DAMM HELPFUL !
@gmanikantasai3655
@gmanikantasai3655 5 месяцев назад
Awesome explanation brother💯💯
@acoustic_ng8706
@acoustic_ng8706 3 года назад
Very helpful ! Thank you Anuj bhai !
@RupeshYadav-kt5dv
@RupeshYadav-kt5dv Год назад
Good job 👏 👍 👌
@vaibhavsomani5161
@vaibhavsomani5161 3 года назад
Hash Code is basically the Memory Reference of that object so what is need for doing the hashing by Modulo and all.
@shriduttpatel1350
@shriduttpatel1350 2 года назад
Thank you @Anuj bhaia. It was really help full. Please do not stop making videos like this😀.
@AnujBhaiya
@AnujBhaiya 2 года назад
If it was really helpful, I will never stop making videos like this 🤗
@nishantaggarwal830
@nishantaggarwal830 3 года назад
It was very interesting and helpful
@er.skelafahmed
@er.skelafahmed 3 года назад
Yes bhaiya its really helpful thank you 😀
@sathishrajasekar1155
@sathishrajasekar1155 3 года назад
Thank you Anuj, The Video was helpful.
@ashutoshpandey4171
@ashutoshpandey4171 2 года назад
Thanks for the effort, anuj bhaiya
@sonam3531
@sonam3531 2 года назад
Thanks , it was good information.
@debasispaul4410
@debasispaul4410 2 года назад
it was helpful
@YashvardhanBaid
@YashvardhanBaid Год назад
Amazing explanation, thanks man!
@abilashappat9640
@abilashappat9640 3 года назад
Very helpful indeed
@shubhamdudhe5737
@shubhamdudhe5737 3 года назад
Bhaiya when we read tree and graph concept please make vedio for that particular topic please bhaiya 🤗
@CodeCult413
@CodeCult413 3 года назад
Excellent explanation bhai. Bhai, on which basis an initial length of hash table get decided?? Is it same like an internal working of arraylist for initial length of hashtable or something else?? And bhai, please increase the frequency of videos on DSA-ONE. I'm eagerly waiting for upcoming videos.
@nandiniverma5273
@nandiniverma5273 2 года назад
It was helpful , Thankyou for deep Knowledge
@jainikprajapati1632
@jainikprajapati1632 2 года назад
Yes it is useful 👍 thanks 😀
@rahulsrivastava1040
@rahulsrivastava1040 2 года назад
Anuj bhaiya op❣️❣️
@ranjeet5806
@ranjeet5806 2 года назад
Great explanation, really helpful.
@sumedhtayade821
@sumedhtayade821 Год назад
Bhaiyya, Hashing ek data compression algorithm hai kya?
@anuj5927
@anuj5927 2 года назад
Yes it was helpful :)
Далее
01. Internal Working of HashMap & Java-8 Enhancement
19:11