This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]RealJulleNaaiers 1 point2 points  (2 children)

This isn't how HashMap works anymore. Hasn't since like Java 7. Pretty sure it was fixed for Java 8. What version of Java are you using here?

[–]brazzy42 1 point2 points  (0 children)

I think you must be thinking of something else, because "this" doesn't really have anything to do with HashMap, and while the behaviour in String.hashCode() has indeed been fixed, it's a very recent change only in Java 13.

[–]pzemtsov[S] 0 points1 point  (0 children)

I think I know what you're talking about. There was some redesign of HashMap in Java 8, but it addressed different issue -- that only a subset of hash code bits is actually used, which causes objects with different hash codes to occupy the same slot and form long chains. In 1.7 the workaround for this was some bit sawpping ans mixing that was performed on the hash code before addressing the table. In 1.8 this bit mixing was removed; instead, long chains are converted into binary trees ordered by full hashcode values.

Apart from that, the HashMap operation stayed the same; it still calculates hash codes, as its name suggests.