Originally posted by Damodara Reddy: Iam sorry Paul Sturrock, Does hashmap allow null keys, I heard that it allows one null key, is it? If so what might be the reason giving us that option?
Yes, though obviously you can only have one null key. If you try to put another value in the Map with a null key it replaces the first value, since Maps are made up of key/value pairs. Hashtables don't allow null keys or values (well, the compiler will allow them but you'll get a NullPointerException when you run your program).
Originally posted by Damodara Reddy: Hai Paul Sturrock, can you clear me about this issue..? In which situation/scenario we would go for inserting a value with null key into HashMap...?
Personally, I always thought it was kindof silly to allow a null key -- I don't think that I ever needed it. But hey... It's a general use collection. There is no reason to justify everything. The designers of the collection may have simply decided to allow any key, including null.
Thanks for your reply Henry Wong. I have one more issue regarding HashMap and Hashtable. When the synchronization comes into picture, which one is efficient among the bellow, using HashMap in a synchronized block, or using a Hashtable...?
Originally posted by Damodara Reddy: Thanks for your reply Henry Wong. I have one more issue regarding HashMap and Hashtable. When the synchronization comes into picture, which one is efficient among the bellow, using HashMap in a synchronized block, or using a Hashtable...?
This question gets asked quite frequently - a search in our Thread forum should give a lot to read. If you still have questions, I'd suggest to start a new topic there...
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus