Hash code caching

The equals() and hashCode() section discussed equals() and hashCode(). Hash codes should be calculated every time they are involved in hashing specific activities (for example, searching an element in a collection). Since String is immutable, every string has an immutable hash code that can be cached and reused as it cannot be changed after string creation. This means that hash codes of strings can be used from the cache instead of recalculating them at each usage. For example, HashMap hashes its keys for different operations (for example, put(), get()), and if these keys are of the String type, then hash codes will be reused from the cache instead of recalculating them.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.149.249.174