📜  为什么 String 是 Java 中流行的 HashMap 键? - Java 代码示例

📅  最后修改于: 2022-03-11 14:52:34.491000             🧑  作者: Mango

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