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 difference between hashset and treeset in java?

1 Answers  


Can we have 2 main methods in java class?

1 Answers  


What is generic type?

1 Answers  


What are listeners in java and explain ?

2 Answers   TCS,


What is meant by main method?

1 Answers  


Explain the term serialization?

10 Answers   Wipro,


what is the difference between pagecontext and servletcontext?

5 Answers   JBA Infotech, TCS,


diff between abstract methods and interfaces with programing (code) example?

2 Answers  


Which is better list or arraylist in java?

1 Answers  


Is there memory leaks in java?

3 Answers  


What are drawbacks of singleton class?

1 Answers  


What is encapsulation? Elaborate with example?

1 Answers   BMC,


Categories