If a collection is declared and populated but its values are never read anywhere in the code, it can be considered unused. This often arises from incomplete refactoring, copy-pasting errors, or typos. Unused collections can lead to wasted memory and degraded application performance. Additionally, their presence makes the code harder to read and understand.
Remove unused collection.
int getLength(String a, String b, String c) {
List<String> strings = new ArrayList<>(); // Noncompliant: List is declared and populated but never read.
strings.add(a);
strings.add(b);
strings.add(c);
return a.length() + b.length() + c.length();
}
int getLength(String a, String b, String c) {
return a.length() + b.length() + c.length();
}