Why string is popular hashmap key in java?



Why string is popular hashmap key in java?..

Answer / vishalshetkar

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 keys in a Map and its processing is fast than other HashMap key objects. This is why String is mostly used Object as HashMap keys.

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More Core Java Interview Questions

What method is used to compare two strings ?

4 Answers  


Can a static block throw exception?

0 Answers  


What access modifiers can be used for methods?

0 Answers  


What are 5 boolean operators?

0 Answers  


What is primitive array?

0 Answers  






what is the major difference between linkedlist and arraylist in java?

0 Answers   IBS,


What is the this keyword?

0 Answers  


What is the final class modifier?

0 Answers  


Can we write a class without main method in java?

0 Answers  


Difference between linkedlist and arraylist.

0 Answers  


Do I need java on my computer?

0 Answers  


What is the difference between keyword and identifier?

0 Answers  


Categories