File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hashtable allowing null values

 
Ra Sank
Greenhorn
Posts: 14
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Wirianto Djunaidi
Ranch Hand
Posts: 210
Ruby Ubuntu VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
because you are passing a string that contains the value "null" instead passing null keyword that represent nothing.
 
Ra Sank
Greenhorn
Posts: 14
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20372
44
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That code will throw a NullPointerException with Hashtable.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic