aspose file tools*
The moose likes Java in General and the fly likes How to check that if same key alreay exists in Hashtable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "How to check that if same key alreay exists in Hashtable" Watch "How to check that if same key alreay exists in Hashtable" New topic
Author

How to check that if same key alreay exists in Hashtable

ram gaurav
Ranch Hand

Joined: Mar 29, 2006
Posts: 208
HI

Like , we make Hashtable t = new Hashtable();

t.put("a","A");
t.put("a","B");

then will it calls the equals methord to check that the key already exists in that or what methord it uses for this.

Thanks
Regards
Gaurav
Peter Chase
Ranch Hand

Joined: Oct 30, 2001
Posts: 1970
You can use containsKey() to check if the key is there beforehand. Or you can look at the return value from put() to see what, if any, value was replaced by your put().

By the way, unless this is legacy code that you cannot change, do not use Hashtable. It is an old class with pointless, slow synchronisation. Use HashMap instead.


Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.
ram gaurav
Ranch Hand

Joined: Mar 29, 2006
Posts: 208
Thanks a lot
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to check that if same key alreay exists in Hashtable