Does HashTable maintains the insertion order?

后端 未结 5 805
醉酒成梦
醉酒成梦 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:24

    From Map Javadoc.

    The order of a map is defined as the order in which the iterators on the map's collection views return their elements. Some map implementations, like the TreeMap class, make specific guarantees as to their order; others, like the HashMap class, do not.

    Also it's very useful to look inside the code of Hashtable and HashMap.

提交回复
热议问题