This week's book giveaway is in the Design forum.
We're giving away four copies of Building Microservices and have Sam Newman 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 Building Microservices this week in the Design forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Hashtable allowing null values" Watch "Hashtable allowing null values" New topic
Author

Hashtable allowing null values

Ra Sank
Greenhorn

Joined: Jun 02, 2008
Posts: 14
Hi,

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
Greenhorn

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
Sheriff

Joined: Oct 27, 2005
Posts: 20080
    
  30

That code will throw a NullPointerException with Hashtable.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions How To Answer Questions
 
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
 
subject: Hashtable allowing null values
 
It's not a secret anymore!