Is there a way to use simple Java for-each loop over Eclipse Collections maps?
I am looking for something like this (but for Eclipse Collections maps):
for (Map.Entry<Integer, String> entry : map.entrySet()) {
}
... but I can't find anything like it for Eclipse Collections maps.
Of course I know this type of Eclipse Collections iterations:
import org.eclipse.collections.impl.map.mutable.primitive.IntObjectHashMap;
public class Test {
public static void main(String[] args) {
IntObjectHashMap<String> map = new IntObjectHashMap<>();
map.put(1, "one");
map.put(2, "two");
int i = 0;
map.forEachKeyValue((int key, String val) -> {
i++; // Compilation error.
System.out.println("key: " + key + ", val: " + val);
});
}
}
... but this construct has some drawbacks, for example I don't have easy access to the surrounding local variables (as shown in the example above, which example will not compile due to incorrect access to the local variable i
).
Any ideas how to write simple loop over Eclipse Collections maps?