Which of the following statements is true about HashMap and Hashtable?

Prepare for the Revature Test with our comprehensive study material. Use flashcards and multiple-choice questions, each with hints and explanations. Get exam-ready now!

The statement that Hashtable is thread-safe and does not allow nulls is correct because Hashtable is designed to be used in a multithreaded environment where thread safety is important. It achieves this through synchronized methods, which means that only one thread can access a Hashtable method at a time, preventing data corruption in concurrent situations. Additionally, Hashtable explicitly does not allow any null keys or values, making it a stricter option compared to other map implementations.

In contrast, HashMap allows one null key and multiple null values, and it is not synchronized, meaning it is not inherently thread-safe. While HashMap can be faster than Hashtable due to its lack of synchronization overhead, this is a more nuanced point and depends on specific use cases and operations. Keeping in mind these characteristics, it's clear why option C correctly reflects the essential nature of Hashtable.

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy