Mastering Java: The Ultimate Quiz for 'Thinking in Java'

Disable ads (and more) with a membership for a one time $2.99 payment

Dive into the depths of Java with our quiz based on "Thinking in Java, Fourth Edition" by Bruce Eckel. Test your knowledge, solidify concepts, and prepare for certification with challenging questions and insightful feedback.

Each practice test/flash card set has 50 randomly selected questions from a bank of over 500. You'll get a new set of questions each time!

Practice this question and more.


How can collisions be handled in a hashtable?

  1. Rehashing

  2. External chaining

  3. Linear probing

  4. Using a larger array

The correct answer is: External chaining

In a hashtable, key-value pairs are stored according to their hash code in an array. In case of a collision, i.e. when two or more keys have the same hash code, the elements cannot be stored properly and need to be handled. The most common way to handle this is by using external chaining, where a linked list is created at the index of the array where the collision occurred and all the elements with the same hash code are stored in this linked list. This allows for efficient retrieval of elements and ensures that data is not lost. Rehashing, linear probing, and using a larger array are other techniques used to handle collisions, but they may not be as efficient as external chaining. Rehashing involves creating a new hash function to reassign the elements, linear probing involves storing data in the next available index in the array, and using a larger array increases the size of