Does HashTable maintains the insertion order?

后端 未结 5 769
醉酒成梦
醉酒成梦 2021-01-07 18:57

The following code gives me the output in the same order of insertion. I read the javadoc and they did not even talk about the insertion order. Can someone help me to get th

5条回答
  •  一整个雨季
    2021-01-07 19:12

    No, it does not. To preserve insertion order, instead use java.util.LinkedHashMap (javadoc).

    Also, HashMap is now preferred over Hashtable, because Hashtable has unnecessary concurrency overhead. (See Differences between HashMap and Hashtable?.)

提交回复
热议问题