HashMap - how it works?
With maps we can access stored objects (values) using keys assigned to them. One of Map interface implementation is HashMap class. In this article we will have a look how HashMap can be used and how it works under the hood. Basic Usage Lets have a look at basic usage of HashMap : We have used HashMap to be able to quickly map a person's name to his car. It is a typical use case of a map. As you can see Car class overrides two methods from Object class - hashCode() and equals() . Those will be used by HashMap internally, as described in next section. It is important to remember two things: hashCode() is used to assign a number to an object. There is a contract between hashCode() and equals() which must be fulfilled - when equals() returnes true for compared objects, then hashCode() values must be the same for both objects. To learn more about hashCode() have a look at the artcile - hashCode() - how it works? How it works under the