HashMap stores key-value pairs using hashing (O(1) average get/put). Since Java 8, when a hash bucket has more than 8 collisions, it converts from a linked list to a balanced Red-Black Tree for O(log n) worst-case performance.
Important: If you use a custom class as a HashMap key, always override both equals() and hashCode()!