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

Discussion

Which of these statements about what a HashSet is built on internally is correct?

  • A.A balanced binary tree, ordered by hash code.
  • B.An array that is re-sorted after every insertion.
  • C.A linked list, which is why membership tests are linear.
  • D.A HashMap, in which the elements are the keys.

Answer: D

The javadoc says the class is backed by a HashMap instance, with the elements as keys and a shared dummy value. That explains why the two classes have identical requirements on equals and hashCode, and identical silence about iteration order.

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

Post your comment

Please log in or register to post a comment.