File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Hashtable allowing null values Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Hashtable allowing null values" Watch "Hashtable allowing null values" New topic

Hashtable allowing null values

Ra Sank

Joined: Jun 02, 2008
Posts: 14

I have tried the below code and it is allowing both null as key as well as values. based on difference between HashMap and Hashtable several tutorials mentioning null is not allowable in Hashtable afterwards of Synchronized difference. Kindly clarify if you have any idea on this.
If these statements are correct then is there any other difference between HashMap and Hashtable?

Learning Java.
Wirianto Djunaidi
Ranch Hand

Joined: Mar 20, 2001
Posts: 210

because you are passing a string that contains the value "null" instead passing null keyword that represent nothing.
Ra Sank

Joined: Jun 02, 2008
Posts: 14
Hi Wirianto,

Thanks for your updates.

Can you please tell me whether i can do like this for the check

ht.put(null,null); Which doesnt affect the Hashtable?.
Rob Spoor

Joined: Oct 27, 2005
Posts: 19719

That code will throw a NullPointerException with Hashtable.

How To Ask Questions How To Answer Questions
It is sorta covered in the JavaRanch Style Guide.
subject: Hashtable allowing null values