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 |
What method is used to compare two strings ?
Can a static block throw exception?
What access modifiers can be used for methods?
What are 5 boolean operators?
What is primitive array?
what is the major difference between linkedlist and arraylist in java?
What is the this keyword?
What is the final class modifier?
Can we write a class without main method in java?
Difference between linkedlist and arraylist.
Do I need java on my computer?
What is the difference between keyword and identifier?