contentEquals

Platform and version requirements: JVM (1.5), JS (1.5), Native (1.5)
infix fun CharSequence?.contentEquals(
    other: CharSequence?
): Boolean
For Common, JS, Native

Returns true if the contents of this char sequence are equal to the contents of the specified other, i.e. both char sequences contain the same number of the same characters in the same order.

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

fun main(args: Array<String>) {
//sampleStart
val stringBuilder = StringBuilder()
stringBuilder.append("Kot").append("lin")
println(stringBuilder) // Kotlin
println("stringBuilder contentEquals "Kotlin" is ${stringBuilder contentEquals "Kotlin"}") // true

stringBuilder.setCharAt(0, 'k')
println(stringBuilder) // kotlin
println(""Kotlin".contentEquals(stringBuilder) is ${"Kotlin".contentEquals(stringBuilder)}") // false
println(""Kotlin".contentEquals(stringBuilder, ignoreCase = true) is ${"Kotlin".contentEquals(stringBuilder, ignoreCase = true)}") // true
//sampleEnd
}
For JVM

Returns true if the contents of this char sequence are equal to the contents of the specified other, i.e. both char sequences contain the same number of the same characters in the same order.

If this CharSequence is a String and other is not null then this function behaves the same as String.contentEquals.

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

fun main(args: Array<String>) {
//sampleStart
val stringBuilder = StringBuilder()
stringBuilder.append("Kot").append("lin")
println(stringBuilder) // Kotlin
println("stringBuilder contentEquals "Kotlin" is ${stringBuilder contentEquals "Kotlin"}") // true

stringBuilder.setCharAt(0, 'k')
println(stringBuilder) // kotlin
println(""Kotlin".contentEquals(stringBuilder) is ${"Kotlin".contentEquals(stringBuilder)}") // false
println(""Kotlin".contentEquals(stringBuilder, ignoreCase = true) is ${"Kotlin".contentEquals(stringBuilder, ignoreCase = true)}") // true
//sampleEnd
}
Platform and version requirements: JVM (1.5), JS (1.5), Native (1.5)
fun CharSequence?.contentEquals(
    other: CharSequence?, 
    ignoreCase: Boolean
): Boolean
For Common, JS, Native

Returns true if the contents of this char sequence are equal to the contents of the specified other, optionally ignoring case difference.

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

fun main(args: Array<String>) {
//sampleStart
val stringBuilder = StringBuilder()
stringBuilder.append("Kot").append("lin")
println(stringBuilder) // Kotlin
println("stringBuilder contentEquals "Kotlin" is ${stringBuilder contentEquals "Kotlin"}") // true

stringBuilder.setCharAt(0, 'k')
println(stringBuilder) // kotlin
println(""Kotlin".contentEquals(stringBuilder) is ${"Kotlin".contentEquals(stringBuilder)}") // false
println(""Kotlin".contentEquals(stringBuilder, ignoreCase = true) is ${"Kotlin".contentEquals(stringBuilder, ignoreCase = true)}") // true
//sampleEnd
}

Parameters

ignoreCase - true to ignore character case when comparing contents.

For JVM

Returns true if the contents of this char sequence are equal to the contents of the specified other, optionally ignoring case difference.

If this CharSequence is a String, other is not null and ignoreCase is false then this function behaves the same as String.contentEquals.

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

fun main(args: Array<String>) {
//sampleStart
val stringBuilder = StringBuilder()
stringBuilder.append("Kot").append("lin")
println(stringBuilder) // Kotlin
println("stringBuilder contentEquals "Kotlin" is ${stringBuilder contentEquals "Kotlin"}") // true

stringBuilder.setCharAt(0, 'k')
println(stringBuilder) // kotlin
println(""Kotlin".contentEquals(stringBuilder) is ${"Kotlin".contentEquals(stringBuilder)}") // false
println(""Kotlin".contentEquals(stringBuilder, ignoreCase = true) is ${"Kotlin".contentEquals(stringBuilder, ignoreCase = true)}") // true
//sampleEnd
}

Parameters

ignoreCase - true to ignore character case when comparing contents.

Platform and version requirements: JVM (1.0)
fun String.contentEquals(charSequence: CharSequence): Boolean

Returns true if this string is equal to the contents of the specified CharSequence, false otherwise.

Note that if the CharSequence argument is a StringBuffer then the comparison may be performed in a synchronized block that acquires that StringBuffer's monitor.

Platform and version requirements: JVM (1.0)
fun String.contentEquals(
    stringBuilder: StringBuffer
): Boolean

Returns true if this string is equal to the contents of the specified StringBuffer, false otherwise.

This function compares this string and the specified StringBuffer in a synchronized block that acquires that StringBuffer's monitor.

© 2010–2021 JetBrains s.r.o. and Kotlin Programming Language contributors
Licensed under the Apache License, Version 2.0.
https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.text/content-equals.html