top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

Why String is popular HashMap key in Java?

0 votes
575 views
Why String is popular HashMap key in Java?
posted Jan 18, 2018 by Frank Lee

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

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 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.

answer Jan 19, 2018 by Jon Deck
...