This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Java in General and the fly likes Hashtable ???? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Hashtable ????" Watch "Hashtable ????" New topic

Hashtable ????

Deepika Wadhwa
Ranch Hand

Joined: Aug 05, 2000
Posts: 57
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

jason adam
Chicken Farmer ()
Ranch Hand

Joined: May 08, 2001
Posts: 1932
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
Bosun Bello
Ranch Hand

Joined: Nov 06, 2000
Posts: 1510
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.


So much trouble in the world -- Bob Marley
jason adam
Chicken Farmer ()
Ranch Hand

Joined: May 08, 2001
Posts: 1932
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?
Consider Paul's rocket mass heater.
subject: Hashtable ????
Similar Threads
I defined an equals method, but Hashtable ignores it. Why?
Collections.synchronizedMap or thread safe classes in collection which one is better?
Hashtable casting error
Passing my object to one to other activity
Reg: HashMap