# 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"));

You Want To Have Those Changes Done Automatically?

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

# Properties

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