String.repeat() can be used
Reports loops that can be replaced with a single String.repeat() method (available since Java 11).
Example:
After the quick-fix is applied:
Locating this inspection
- By ID
Can be used to locate inspection in e.g. Qodana configuration files, where you can quickly enable or disable it, or adjust its settings.
StringRepeatCanBeUsed- Via Settings dialog
Path to the inspection settings via IntelliJ Platform IDE Settings dialog, when you need to adjust inspection settings directly from your IDE.
By default, the inspection may wrap count with Math.max(0, count) if it cannot prove statically that count is not negative. This is done to prevent possible semantics change, as String.repeat() rejects negative numbers. Use the Add Math.max(0,count) to avoid possible semantics change option to disable this behavior if required.
Similarly, a string you want to repeat can be wrapped in String.valueOf to prevent possible NullPointerException if it's unknown whether it can be null.
This inspection only reports if the language level of the project or module is 11 or higher.
Inspection ID: StringRepeatCanBeUsed
New in 2019.1
Inspection options
Here you can find the description of settings available for the String.repeat() can be used inspection, and the reference of their default values.
- Add Math.max(0, count) to avoid possible semantics change
Option ID:
ADD_MATH_MAXDefault value:
Selected
Suppressing Inspection
You can suppress this inspection by placing the following comment marker before the code fragment where you no longer want messages from this inspection to appear:
More detailed instructions as well as other ways and options that you have can be found in the product documentation:
Inspection Details | |
|---|---|
By default bundled with: |