String Builder in Kotlin

Level 3101 keystrokes

Builds a string piece by piece with the buildString function.

Kotlin code

// buildString gives the block a StringBuilder and returns the final String
1val result = buildString {
// append adds text to the end of the builder
2 append("Hello")
// Appending to one builder avoids creating a new string each time
3 append(", ")
4 append("World")
5 append("!")
6}
// Prints Hello, World!
7println(result)

Output

Hello, World!
Practice typing this code

Practice typing this code. Results are not recorded in the rankings.

Symbols in this code

The symbols you type in this Kotlin code and how often they appear.

  • "× 8
  • (× 5
  • )× 5
  • ,× 1
  • !× 1
  • {× 1
  • }× 1
  • =× 1

More Kotlin examples at level 3

← Kotlin typing practice