HashMap can keep always the same order?
This question already has an answer here:
如果您使用LinkedHashMap,则顺序将保持不变(即,默认情况下,键将始终按照插入到Map中的顺序迭代)。
If the keys and values are always the same, the map size is the same, and the HashMap
is initialized in the same way, then yes. However for guaranteed iteration order, use a LinkedHashMap
.
上一篇: 谁在Java中更快的hashmap.get或treemap.get
下一篇: HashMap可以始终保持相同的顺序?