Inspectopedia
 
2024.3

Manual array to collection copy

Warning
New
Last modified: 03 December 2024

Reports code that uses a loop to copy the contents of an array into a collection.

A shorter and potentially faster (depending on the collection implementation) way to do this is using Collection.addAll(Arrays.asList()) or Collections.addAll().

Only loops without additional statements inside are reported.

Example:

After the quick-fix is applied: