# 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
Tags
# Code Changes
Pre
List<String> list = new ArrayList<>();
list.addAll(Arrays.asList("value1", "value2"));
Post
List<String> list = new ArrayList<>(Arrays.asList("value1", "value2"));
🛠️ Auto-refactor Available
You can auto-refactor this with jSparrow.
Drop this button to your Eclipse IDE workspace to install jSparrow for free:
Need help? Check out our installation guide.
# Properties
Property | Value |
---|---|
Rule ID | RemoveCollectionAddAll |
First seen in jSparrow version | 3.15.0 |
Minimum Java version | 1.2 |
Remediation cost | 2 min |