Fabio Insaccanebbia has come up with another fine rule for PMD - AvoidArrayLoops finds for/while loop array copies that can be replaced with a call to System.arraycopy. For example, this:
can be replaced with this:
Using System.arraycopy
is more concise and is faster, too, since it's usually implemented with native code.
Running this rule on the JDK found some straightforward replacement candidates, such as this snippet from MessageFormat.setFormats
:
You'll find this rule checked in to the PMD CVS repository in the optimizations ruleset; and a PMD 3.5 release is not far away. Thanks again to Fabio for his excellent contributions!