v1.8.10
  • Solutions
    • Multiplatform
    • Server-side
    • Data science
    • Android
  • Docs
  • Community
  • Teach
  • Play
    • Playground
    • Hands-on
    • Examples
    • Koans
← Docs
kotlin-stdlib / kotlin.text / repeat

repeat

Common
JVM
JS
Native
1.0
fun CharSequence.repeat(n: Int): String
(Common source) (JVM source) (JS source) (Native source)

Returns a string containing this char sequence repeated n times.

import java.util.Locale
import kotlin.test.*

fun main(args: Array<String>) {
//sampleStart
println("Word".repeat(4)) // WordWordWordWord
println("Word".repeat(0)) //
//sampleEnd
}

Exceptions

IllegalArgumentException - when n < 0.

Stay in touch:
  • Contributing to Kotlin
  • Releases
  • Press Kit
  • Security
  • Blog
  • Issue Tracker
  • Brand assets
  • Careers
Kotlin™ is protected under the Kotlin Foundation and licensed under the Apache 2 license.
Supported and developed by JetBrains