This week's book giveaway is in the Cloud/Virtualizaton forum.
We're giving away four copies of Mesos in Action and have Roger Ignazio on-line!
See this thread for details.
Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Map does not support iterator ?

 
jose chiramal
Ranch Hand
Posts: 266
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why Map does not support iterator ?

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

 
Rob Spoor
Sheriff
Pie
Posts: 20532
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
James Sabre
Ranch Hand
Posts: 781
Java Netbeans IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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().
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic