aspose file tools*
The moose likes Beginning Java and the fly likes How to get values in hashtable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "How to get values in hashtable" Watch "How to get values in hashtable" New topic
Author

How to get values in hashtable

vin Hari
Ranch Hand

Joined: Nov 16, 2006
Posts: 161
Hello all,
Iam using hashtable for my program through which i can fetch keys using
Hashtable(name).key()

but i wnat to fetch values how to do please if any functions are there please tell me.
thanks in advance
Qunfeng Wang
Ranch Hand

Joined: Jan 28, 2005
Posts: 425


To be or not to be. It's a question.
Amit Arora
Ranch Hand

Joined: Jun 14, 2007
Posts: 30
For fetching all the values from hash table in a set use:

Set set = ht.values()

where ht is object of Hashtable

but to get a value corresponding to a key use

Object o = ht.get("key");

and down cast it to required object


Amit Arora<br />SCJP 1.4, SCWCD
Muhammad Saifuddin
Ranch Hand

Joined: Dec 06, 2005
Posts: 1321

the link will guide you more on that.. http://java.sun.com/developer/TechTips/1998/tt0316.html#tip2

Suggestion: best place to ask this question in Java in General forum.


Saifuddin..
[Blog][Linkedin] How To Ask Questions On JavaRanch My OpenSource
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19543
    
  16

Originally posted by Amit Arora:
For fetching all the values from hash table in a set use:
Set set = ht.values()

That should be Collection c = ht.values();

values() returns a collection, it's keySet() and entrySet() that return Sets.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Amit Arora
Ranch Hand

Joined: Jun 14, 2007
Posts: 30
Yes that is collection returned by values method.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: How to get values in hashtable
 
Similar Threads
Retrieve the results from the Hashtable by looping
Change Increment index of for loop in stored procedure
Regarding HashTable in Javascript
Axis and custom socketFactory
Change Increment index of for loop in stored procedure