Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Loop through HashMap...

Status
Not open for further replies.

patnim17

Programmer
Jun 19, 2005
111
US
Hi,
I need to loop through a HashMap object which has Key and Value pairs, both of type String, but I do not know any of the Keys or the values...
How can I loop through this HashMap and get both the Key and the Value in one loop...

The reason I want to get the Key and the Value in one loop is to build a XML out of it...

Thanks in Adv.
Nims..
 
You can obtain a set of keys with keySet() and iterate through it obatining the values.

Cheers,

Dian
 
Hi,
thanks a lot. Is it possible to get the data, value from a HashMap using the index..like say if I have key-value pairs in my HashMap as
1."cow"-"Milk"
2."Dog"-"Bark"
etc...is it possible to get the key-value pair by index..something like HashMap(0) ..

nims
 
Use an ArrayList instead of a HashMap, then you can access elements by index.

Cheers,
Dian
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top