File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Map does not support iterator ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Map does not support iterator ?" Watch "Map does not support iterator ?" New topic
Author

Map does not support iterator ?

jose chiramal
Ranch Hand

Joined: Feb 12, 2010
Posts: 266
Why Map does not support iterator ?

We need to use static interface Map.Entry every time to overcome this .

Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19693
    
  20

What do you mean, access Map.Entry? Do you mean that you iterate over the entrySet() each time? That's how it works.

There are actually three views you can use: keySet() for only the keys, values() for only the values and entrySet() for both. With entrySet() you need to have something that also contains both, and that's Map.Entry. That's why the iterator returns those.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
James Sabre
Ranch Hand

Joined: Sep 07, 2004
Posts: 781

jose chiramal wrote:Why Map does not support iterator ?

We need to use static interface Map.Entry every time to overcome this .



I think I must be missing something! If you want to iterate of the keys then use Map.keySet(). If you want to iterate of the values then use Map.values().

Are you wanting an iterator() method to provide an Iterator<Map.Entry<K,V> > ? If so then just use Map.entrySet().iterator().


Retired horse trader.
 Note: double-underline links may be advertisements automatically added by this site and are probably not endorsed by me.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Map does not support iterator ?