I have this loop:
for (Map.Entry<Integer, String> entry: collection.entrySet()) {
}
I'd like to compare entry and the next one after that. How would I do it?
I have this loop:
for (Map.Entry<Integer, String> entry: collection.entrySet()) {
}
I'd like to compare entry and the next one after that. How would I do it?
As you loop over you could set a variable called oldEntry for example (initialized to null) and use that in the way you want.
Map.Entry<Integer,String> oldEntry = null;
for (Map.Entry<Integer, String> entry: collection.entrySet()) {
if (oldEntry != null) doStuff(oldEntry, newEntry);
oldEntry = entry;
}