This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
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 Murach's Java Servlets and JSP this week in the Servlets 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: 19649

That code will throw a NullPointerException with Hashtable.

How To Ask Questions How To Answer Questions
I agree. Here's the link:
subject: Hashtable allowing null values
Similar Threads
enthuware question
Enthuware mock doubt!!
is it a valid jsp code
Sorting Vector of Hashtables by a Hashtable value
What is the difference between Hashtable and HashMap classes?