# Remove Collection::addAll

# Description

In order to apply the rule, the following two statements must occur:

  • A declaration of a local variable storing an instance of java.util.Collection which is initialized with the default constructor.
  • An invocation of java.util.Collection#addAll immediately following the variable declaration.

# Benefits

Reducing lines of code and improving readability.

# Tags

# Code Changes


List<String> list = new ArrayList<>();
list.addAll(Arrays.asList("value1", "value2"));


List<String> list = new ArrayList<>(Arrays.asList("value1", "value2"));

Use a Java Refactoring Tool

No license required

You can review this refactoring on your code without a license by installing jSparrow to your Eclipse IDE. Install the plug-in from Eclipse IDE: Eclipse Marketplace.

System-wide Refactoring

Do you want to automate this refactoring (and many more) to your system-wide code? The automatic application of this system-wide refactoring can be unlocked by acquiring your jSparrow license.

a drawn cute bird pointing at a graph that shows positive results

# Properties

Property Value
Rule ID RemoveCollectionAddAll
First seen in jSparrow version 3.15.0
Minimum Java version 1.2
Remediation cost 2 min