contentEquals

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.

Since Kotlin

1.5

Samples

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

fun main() { 
   //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
}

expect fun CharSequence?.contentEquals(other: CharSequence?, ignoreCase: Boolean): Boolean(source)

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

Since Kotlin

1.5

Parameters

ignoreCase

true to ignore character case when comparing contents.

Samples

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

fun main() { 
   //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
}

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.

Since Kotlin

1.5

Samples

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

fun main() { 
   //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
}

actual fun CharSequence?.contentEquals(other: CharSequence?, ignoreCase: Boolean): Boolean(source)

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

Since Kotlin

1.5

Parameters

ignoreCase

true to ignore character case when comparing contents.

Samples

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

fun main() { 
   //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
}
inline fun String.contentEquals(charSequence: CharSequence): Boolean(source)

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.

Since Kotlin

1.0

inline fun String.contentEquals(stringBuilder: StringBuffer): Boolean(source)

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.

Since Kotlin

1.0

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.

Since Kotlin

1.5

Samples

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

fun main() { 
   //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
}

actual fun CharSequence?.contentEquals(other: CharSequence?, ignoreCase: Boolean): Boolean(source)

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.

Since Kotlin

1.5

Parameters

ignoreCase

true to ignore character case when comparing contents.

Samples

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

fun main() { 
   //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
}

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.

Since Kotlin

1.5

Samples

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

fun main() { 
   //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
}

actual fun CharSequence?.contentEquals(other: CharSequence?, ignoreCase: Boolean): Boolean(source)

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

Since Kotlin

1.5

Parameters

ignoreCase

true to ignore character case when comparing contents.

Samples

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

fun main() { 
   //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
}