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 is the driver class?

0 Answers  


What is the purpose of the strictfp keyword?

0 Answers  


What is the this keyword?

0 Answers  


Which of these methods belong to Thread & Object class? join, yield, sleep, wait, notify

3 Answers   Ericsson,


Why is serialization required?

0 Answers  


When should the method invokelater() be used?

0 Answers  


What is variable declaration and definition?

0 Answers  


List interface?

2 Answers  


What is finalize()?

0 Answers  


How do you take thread dump in java?

0 Answers  


I want to persist data of objects for later use. What is the best approach to do so?

0 Answers  


What is the purpose of void class?

0 Answers  


Categories