Meaningless Drivel is fun!*
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
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: 19656
    
  18

That code will throw a NullPointerException with Hashtable.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
wood burning stoves
 
subject: Hashtable allowing null values
 
Similar Threads
Sorting Vector of Hashtables by a Hashtable value
enthuware question
Enthuware mock doubt!!
is it a valid jsp code
What is the difference between Hashtable and HashMap classes?