0 votes
in JAVA by

Why String is popular HashMap key in Java?

1 Answer

0 votes
by

Since String is immutable, its hashcode is cached at the time of creation and it doesn’t need to be calculated again. This makes it a great candidate for the key in a Map and it’s processing is fast than other HashMap key objects. This is why String is mostly used Object as HashMap keys.

...