aspose file tools*
The moose likes Beginning Java and the fly likes collctions Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "collctions" Watch "collctions" New topic
Author

collctions

sudhakar naga
Greenhorn

Joined: Mar 01, 2010
Posts: 2
hi sir,

How to iterate the map collection.


please give me good solution
Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3838

Hint: Check the Map API


SCJP 5 | SCWCD 5
[How to ask questions] [Twitter]
sudheer kiran
Ranch Hand

Joined: Jun 26, 2008
Posts: 237

remember is not a collection of objects
its a collection of combination of keys and values
so you can iterate thru keys and get corresponding values.
or get a value set and iterate each one .


Sudheer
SCWCD, SCJP 5
learning Freak
Greenhorn

Joined: Jan 20, 2010
Posts: 5
Get the values contained in the Hashmap using the values() of HashMap class which returns Collection object.

Collection c = hmap.values();

obtain iterator for the collection.

Iterator it = c.iterator();

Iterate through Hashmap values iterator

while(it.hasNext()){
System.out.println(it.next());
}

learning Freak
Greenhorn

Joined: Jan 20, 2010
Posts: 5
One more way Iterating with the Keys .

keySet() returns the set of keys contained in HashMap object .

Set s = hmap.keySet();

Iterator it = s.iterator();

while(it.hasNext()){
System.out.println(it.next());
}
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

@learning Freak: Please see the JavaRanch naming policy and change your display name to conform with this policy. Thanks!
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: collctions