Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hashtable ????

 
Deepika Wadhwa
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all ,
i just want to know that how can i check my Hashtable whether it contains a value greater than "0".
is there any way do it ???

thanx in advance
Deepika


------------------
 
jason adam
Chicken Farmer ()
Ranch Hand
Posts: 1932
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Depending on what you want to do, there are a couple of options. If by 0 you mean that the hashtable has been created, but nothing is in there, you can do a Hashtable.isEmpty(), which returns true if there is nothing in the hashtable, or false if there is.
You can also use Hashtable.size(), which returns the number of keys in your hashtable. This way, if you want to know that there are more than 0, or more than 1, or whatever, you can test for that.
Hope that helps
Jason
 
Bosun Bello
Ranch Hand
Posts: 1510
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you want to check it's contents for a value > 0, then you have to enumerate thru the collection, checking/retrieving, and converting to an int, if need be, each element if it's greater than zero.

Bosun
 
jason adam
Chicken Farmer ()
Ranch Hand
Posts: 1932
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wait, are you wanting to know if your Hashtable contains a number that is greater than 0, or if your Hashtable contains more than 0 elements?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic