Timeline for answer to How do I efficiently iterate over each entry in a Java Map? by pkaeding
Current License: CC BY-SA 3.0
Post Revisions
8 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Feb 6, 2018 at 22:32 | history | edited | Peter Mortensen | CC BY-SA 3.0 |
Added a cross-reference (as user names may change at any time).
|
| Jan 21, 2017 at 8:09 | comment | added | user5778069 | This solution will not work if you have a integer key and String key. | |
| Jan 14, 2015 at 2:35 | comment | added | pkaeding |
@JohnK try importing java.util.Map.Entry.
|
|
| Jan 10, 2015 at 0:06 | comment | added | JohnK |
IntelliJ is giving me errors on Entry thisEntry = (Entry) entries.next();: doesn't recognize Entry. Is that pseudocode for something else?
|
|
| Jan 10, 2012 at 15:42 | comment | added | pkaeding |
@jpredham You are right that using the for construct as for (Entry e : myMap.entrySet) will not allow you to modify the collection, but the example as @HanuAthena mentioned it should work, since it gives you the Iterator in scope. (Unless I'm missing something...)
|
|
| Oct 20, 2009 at 13:20 | comment | added | jai | Prefer for-loop than while.. for(Iterator entries = myMap.entrySet().iterator(); entries.hasNext(); ) {...} With this syntax the 'entries' scope is reduced to the for loop only. | |
| Sep 5, 2008 at 21:28 | history | edited | pkaeding | CC BY-SA 2.5 |
added note about 1.4/1.5
|
| Sep 5, 2008 at 21:15 | history | answered | pkaeding | CC BY-SA 2.5 |