why HashTable not allow null key and value

Answer Posted / eknath

To successfully store and retrieve objects from a hashtable,
the objects used
as keys must implement the hashCode method and the equals
method.

In a nutshell, since null isn't an object, you can't call
.equals() or .hashCode() on it, so the Hashtable can't
compute a hash to use it as a key.

HashMap is newer, and has more advanced capabilities, which
are basically just an improvement on the Hashtable
functionality. As such, when HashMap was created, it was
specifically designed to handle null values as keys and
handles them as a special case.

Specifically, the use of null as a key is handled like this
when issuing a .get(key):

(key==null ? k==null : key.equals(k))

Is This Answer Correct ?    11 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is the argument in java?

497


Can we initialize the final blank variable?

584


What is object english?

585


What does jre stand for?

609


What is bool mean?

568






Hi Anyone know the model / questions of the Federal bank sample questions for the post of Specialist Officers - Programmers. Please post if anyone have..

1824


What are jee technologies?

535


What is the importance of main method in Java?

575


How many arguments can be passed to main ()?

525


What are the files generated after using IDL to java compiler?

589


How do you do descending order in java?

521


What is lifetime variable?

525


How are the elements of a gridbaglayout organized?

546


Say any two properties in beans?

636


Why Do I Get A "permission Denied" Error After Downloading The .jnlp Java Launcher For The Vkvm?

633