Skip to Main Content

Java APIs

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

foreach on maps

843793Aug 29 2003 — edited Mar 14 2006
I proposed this a while ago, and as far as i remember everybody nodded, said yes, and then got on with their lives without a second thought.

To iterate through the elements in a Map with the new for loops, you have to do:

Map <String, Widget> mymap = ...;
for (Map.Entry <String, Widget> entry : mymap) {
String key = entry.getKey();
Widget value = entry.getValue();
...
}

I'd far rather this was handled with a syntax similar (but not necessarily identical) to this:

Map <String, Widget> mymap = ...;
for (String key, Widget value : mymap) {
...
}

Like i said, nobody had an objection - even the members of the Java team i spoke to - but it seems to have been forgotten about. Is there a good reason?
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 11 2006
Added on Aug 29 2003
15 comments
404 views