Inspectopedia Help

Unnecessary conversion to 'String'

Reports unnecessary calls to static methods that convert to string, like String.valueOf() or Integer.toString(). Such calls are unnecessary when used, in string concatenations or, as arguments of library methods where explicit string conversion is not needed.

Example:

System.out.println("Number: " + Integer.toString(count));

After the quick-fix is applied:

System.out.println("Number: " + count);

Library methods that don't require explicit string conversion:

  • Classes java.io.PrintWriter, java.io.PrintStream

    • print(), println()

  • Classes java.lang.StringBuilder, java.lang.StringBuffer

    • append()

  • Class org.slf4j.Logger

    • trace(), debug(), info(), warn(), error()

Use the Report calls that can be replaced with a concatenation with the empty string option to also report cases where concatenations with the empty string can be used instead of a call to String.valueOf().

Inspection options

Option

Type

Default

Report calls that can be replaced with a concatenation with the empty string

Checkbox

false

Inspection Details

Available in:

IntelliJ IDEA 2023.3, Qodana for JVM 2023.3

Plugin:

Java, 233.SNAPSHOT

Last modified: 13 July 2023