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: 433


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: 19790
    
  20

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to get values in hashtable