Win a copy of Machine Learning Systems: Designs that scale this week in the Scala forum
or Xamarin in Action: Creating native cross-platform mobile apps in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to check that if same key alreay exists in Hashtable  RSS feed

 
Ranch Hand
Posts: 208
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 1970
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
ram gaurav
Ranch Hand
Posts: 208
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot
 
When I was younger I felt like a man trapped inside a woman’s body. Then I was born. My twin is a tiny ad:
Rocket Oven Kickstarter - from the trailboss
https://coderanch.com/t/695773/Rocket-Oven-Kickstarter-trailboss
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!