Forums Register Login

How to check that if same key alreay exists in Hashtable

+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
Thanks a lot
Ruth Stout was famous for gardening naked. Just like this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 1437 times.
Similar Threads
a problem of Hashtable
Map Doubt
Hashtable
Concordancer
Lookup key in HashTable
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 16, 2024 05:51:39.