Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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 multithreading in java?

1054


What do you mean by an interface in java?

1023


How many days will it take to learn java?

929


How to implement an arraylist in java?

1149


How do you sort in ascending order in java?

867


Is hashmap thread safe?

978


When a lot of changes are required in data, which one should be a preference to be used? String or stringbuffer?

1236


Why do we override tostring method in java?

957


How do you calculate square roots?

1156


What are the different http methods?

1028


Explain reverse a linked list recursive java solution?

980


What are different data structures in java?

1037


What is an immutable class? How to create an immutable class?

1058


Why main() method is public, static and void in java ?

1090


What does .equals do in java?

1085