Back to Intellij Community

ConvertToStringTemplate

plugins/kotlin/code-insight/descriptions/resources-en/inspectionDescriptions/ConvertToStringTemplate.html

2025.3-rc-2603 B
Original Source

Reports string concatenation that can be converted to a string template.

Using string templates is recommended as it makes code easier to read.

Example:

fun example() {
      val capitals = mapOf("France" to "Paris", "Spain" to "Madrid")
      for ((country, capital) in capitals) {
          print(capital + " is a capital of " + country)
      }
  }

After the quick-fix is applied:

fun example() {
      val capitals = mapOf("France" to "Paris", "Spain" to "Madrid")
      for ((country, capital) in capitals) {
          print("$capital is a capital of $country")
      }
  }