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

Discussion

Consider how Hashtable differs from HashMap over null. Which statement is correct?

  • A.Both classes accept a null key but reject a null value.
  • B.Hashtable rejects a null key and a null value; HashMap accepts both.
  • C.Hashtable accepts a null key and a null value; HashMap rejects both.
  • D.Both classes accept a null value but reject a null key.

Answer: B

Hashtable is the older synchronized class and throws NullPointerException for either a null key or a null value, whereas HashMap tolerates one null key and any number of null values. Where a synchronized map is genuinely needed, Collections.synchronizedMap around a HashMap is the modern equivalent.

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

Post your comment

Please log in or register to post a comment.