HashMap hashCode collision by example
As we all know Hash is a part of Java Collection framework and stores key-value pairs. HashMap uses hash Code value of key object to locate their possible in under line collection data structure, to be specific it is nothing but array. Hash code value of key object decide index of array where value object get stored. As per hashcode – equals method implementation rules Objects that are equal according to the equals method must return the same hashCode value. & If two objects are not equal according to equals, they are not required to return different hashCode values. As per above statement it is possible that two different object may have same hashcode values, this is called hashcode collision . To overcome this problem concept of bucket has been introduced. All the Value objects whose corresponding Key’s hashcode values are same , they fall under same bucket. Above diagram explains hash code collision. There are three key-value entries are shown , out of which second and thi...
good. all info in one place :)
ReplyDeleteIf you find any conflict then lets update the post :)
ReplyDeleteHi Yogesh.
ReplyDeleteThanks to your post I finally could load a resource stylesheet for my application: I spent more than 4 hours googling everywhere and not finding the right answer.
My mistake was that I wrote:
this.getClass().getResourceAsStream("stylesheet.xsl")
But my file was located in WEB-INF/classes.
Thanks to your post I changed to "/stylesheet.xsl" and now everything works fine.
Thanks again!
@Frederic F. MONFILS You always Welcome :)
ReplyDeleteLife saver! Saved me a couple of hours as well.
ReplyDelete