#14 - linkedhashmap vs hashmap in Java || How LinkedHashMap works internally - Naveen AutomationLabs

preview_player
Показать описание
In this video, I have explained what is LinkedHashMap in Java and How LinkedHashMap works internally.

~~~Subscribe to this channel, and press bell icon to get some interesting videos on Selenium and Automation:

Follow me on my Facebook Page:

Let's join our Automation community for some amazing knowledge sharing and group discussion on Telegram:

Paid courses (Recorded) videos:

Рекомендации по теме
Комментарии
Автор

Great Video Naveen sir !
Can you add some comments or a short video for collision in linked hashmap ? I see many folks have requested for the same . if you could, it would be great :)

arvindhr.a
Автор

Back to back new video 👍😊, thanks for the video Naveen

SarangHoley
Автор

nice one Naveen, was waiting for this

Vishalfootball
Автор

what an amazing explanation..Thank you sir

manikandan
Автор

Good to see a video on the internal implementation of a Collection class!
But, I have an interesting question here :
What if 2 keys have the same hashCode?
As per your logic, they will generate same index. How will you store 2 nodes under the same segment(bucket)?

I think instead of 2 pointers the nodes must have 3 pointers.
1. BackwardNode
2. ForwardNode
3. NextNode to point to a Node belonging to the same index(bucket).

Not sure if LinkedHashSet is implemented this way. Would like to hear from you.

rishibharadwaj
Автор

Hello @Naveen,
I have one question regarding linkedHashMap, as per your explanation, does this mean 1 segment will have only one node created at any given point unlike HashMap where we could have maximum 8 nodes per segment?

flivnrk
Автор

Thanks for the explanation Naveen. You should've explained about Entry which is wrapper of Node.

HashMap.Node subclass for normal LinkedHashMap entries.

static class Entry<K, V> extends HashMap.Node<K, V> {
Entry<K, V> before, after;
Entry(int hash, K key, V value, Node<K, V> next) { super(hash, key, value, next);
}
}

thanga
Автор

You explain really well, Thank you so much

dikshabaluja
Автор

Nice explanation Naveen! do we have any methods to retrieve the previous node from a particular node since it's implementing doubly-linked lists?

sureshgarine
Автор

If same hashcode here for different keys then? what about collision and threshold applies
naveen pls reply

ramyagunaseelan
Автор

How the collision is handled in LinkedHashMap?

nehasinghal
Автор

Hi Naveen, Thank you for this explanation. Just a quick query, what happens here, if the segment index of the second value I am inserting is calculated to be the same as the index of the first value? In your HashMap implementation video example you have had mentioned that the segment index of different values can be the same. Is is not the same for LinkedHashMap?

Thanks!!

chetanpalekar
Автор

Hi, Thank you for the explanation, but I have a question when a collision occurs how the behavior be? because we are already pointing before and after node?

xyfqnme
Автор

If in case of LinkedHashMap collisions is occured then what will happen?

mollamainuddin
Автор

Hi Naveen, can collision occur in the LinkedHasMap also. In that case what happens to the before and after nodes?

socialmedia
Автор

While we are inserting next elements, if we get index is lesser than the previous node, how they will connect before and after and maintains the insertion order. ?

sheshankgolli
Автор

Sir what happens if index for 2 different keys is same.. Then how the two key value pairs will be stored?

RajkumarVishwakarma
Автор

Naveen can you share the collision in case of LinkedHashMap

TheRajatsaluja
Автор

Since index is decided is based on hash code, how is it ordered collection ? What if some key get index of 2 (which is inserted in the end) & what about Collison? Doesn't it happen here?? I understood o/p will be just like i/p tho.

moonshine
Автор

and what will happen when collision happens. Even in HashMap values are stored in the same way. What's the difference between HashMap and LinkedHashMap.

kanishkasrivastava