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

Discussion

Which one of the following statements about what LinkedHashSet guarantees that HashSet does not is true?

  • A.Iteration in the order elements were first inserted.
  • B.Iteration in the natural order of the elements.
  • C.Rejection of null elements.
  • D.Constant-time membership tests.

Answer: A

Correct answer: Iteration in the order elements were first inserted.

LinkedHashSet maintains a doubly linked list through its entries in addition to the hash table, so iteration follows insertion order while lookup remains hash-based. Re-inserting an element already present does not move it, which is why the guarantee is *first* insertion order. Both classes allow a null element and both give constant-time membership tests.

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

Post your comment

Please log in or register to post a comment.