Inspectopedia
 
2024.3

Map.forEach() can be used

Warning
New
Last modified: 03 December 2024

Suggests replacing for(Entry<?,?> entry : map.entrySet()) {...} or map.entrySet().forEach(entry -> ...) with map.forEach((key, value) -> ...).

Example

After the quick-fix is applied:

When the Do not report loops option is enabled, only entrySet().forEach() cases will be reported. However, the quick-fix action will be available for for-loops as well.

This inspection depends on the Java feature 'Lambda methods in collections', which is available since Java 8.

New in 2017.1