Inspectopedia
 
2024.3

Loop can be collapsed with Stream API

Info
New
Last modified: 03 December 2024

Reports loops which can be replaced with stream API calls using lambda expressions.

Such a replacement changes the style from imperative to more functional and makes the code more compact.

Example:

After the quick-fix is applied:

This inspection depends on the Java feature 'Stream and Optional API', which is available since Java 8.