# Remove Collection::addAll

# Properties

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

# 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.

# Code Changes

Pre

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

Post

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

Automatic Application of This Rule

The automatic application of this rule is supported in the following jSparrow version:

# Tags

1
default
You & jSparrow
default

Hey there! May I help you? 😊