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

List methods available in Java Queue interface

1 Answers  


Differentiate between the constructors and methods in java?

0 Answers  


Can we declare main () method as non static?

0 Answers  


How can a class be accessed, If no access modifiers are declared?

4 Answers  


What is a memory leak in java?

0 Answers  


Can we instantiate interface in java?

0 Answers  


What is java util?

0 Answers  


Can we initialize the final blank variable?

0 Answers  


what is a thread?

13 Answers   IBM, SunGard,


What are static variables and functions?

0 Answers   Tech Mahindra,


What is the difference between overriding & overloading?

0 Answers  


What defines function?

0 Answers  


Categories