Why is this an issue?

When the final size of a string or buffer is known in advance, initializing it with the appropriate capacity avoids dynamic resizing during appends. Dynamic resizing consumes additional CPU cycles (for memory allocation and copying) and RAM, leading to unnecessary energy consumption.

Examples

Noncompliant

StringBuilder sb = new StringBuilder(); // Noncompliant
for (int i = 0; i < 100; i++) {
    sb.append(...);
}

Compliant

StringBuilder sb = new StringBuilder(100);
for (int i = 0; i < 100; i++) {
    sb.append(...);
}

Resources