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

Discussion

Consider whether a Set can ever equal a List with the same elements. Which statement is correct?

  • A.Only when both are empty, since neither then has contents to compare.
  • B.No, each interface requires the other operand to be of its own kind.
  • C.Yes, provided the list has no duplicates and the same iteration order.
  • D.Yes, because both define equality by contents alone.

Answer: B

List.equals demands another List and Set.equals demands another Set, so the two are never equal, not even when empty. Within a kind the implementation class does not matter, which is why an ArrayList can equal a LinkedList.

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

Post your comment

Please log in or register to post a comment.