Machine-translated by Google. Questions are authored in English.
Top

Discussion

The iteration order a HashMap guarantees - which of the following is true?

  • A.The natural ordering of the keys.
  • B.Ascending order of the keys' hash codes.
  • C.None; the order is unspecified and may change over time.
  • D.Insertion order.

Answer: C

The javadoc says the class makes no guarantees as to the order, and does not even guarantee the order stays constant over time, since a resize can move entries. LinkedHashMap is what preserves insertion order and TreeMap what sorts by key.

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.