contentEquals

expect infix fun CharSequence?.contentEquals(other: CharSequence?): Boolean

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 samples.*
import java.util.Locale
import kotlin.test.*
fun main() { 
   //sampleStart 
   val stringBuilder = StringBuilder()
stringBuilder.append("Kot").append("lin")
assertPrints(stringBuilder, "Kotlin")
assertTrue(stringBuilder contentEquals "Kotlin")

stringBuilder.setCharAt(0, 'k')
assertPrints(stringBuilder, "kotlin")
assertFalse("Kotlin".contentEquals(stringBuilder))
assertTrue("Kotlin".contentEquals(stringBuilder, ignoreCase = true)) 
   //sampleEnd
}

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

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

Samples

import samples.*
import java.util.Locale
import kotlin.test.*
fun main() { 
   //sampleStart 
   val stringBuilder = StringBuilder()
stringBuilder.append("Kot").append("lin")
assertPrints(stringBuilder, "Kotlin")
assertTrue(stringBuilder contentEquals "Kotlin")

stringBuilder.setCharAt(0, 'k')
assertPrints(stringBuilder, "kotlin")
assertFalse("Kotlin".contentEquals(stringBuilder))
assertTrue("Kotlin".contentEquals(stringBuilder, ignoreCase = true)) 
   //sampleEnd
}

Parameters

ignoreCase

true to ignore character case when comparing contents.

inline 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.


inline 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.


actual infix fun CharSequence?.contentEquals(other: CharSequence?): Boolean

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 samples.*
import java.util.Locale
import kotlin.test.*
fun main() { 
   //sampleStart 
   val stringBuilder = StringBuilder()
stringBuilder.append("Kot").append("lin")
assertPrints(stringBuilder, "Kotlin")
assertTrue(stringBuilder contentEquals "Kotlin")

stringBuilder.setCharAt(0, 'k')
assertPrints(stringBuilder, "kotlin")
assertFalse("Kotlin".contentEquals(stringBuilder))
assertTrue("Kotlin".contentEquals(stringBuilder, ignoreCase = true)) 
   //sampleEnd
}

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

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

Samples

import samples.*
import java.util.Locale
import kotlin.test.*
fun main() { 
   //sampleStart 
   val stringBuilder = StringBuilder()
stringBuilder.append("Kot").append("lin")
assertPrints(stringBuilder, "Kotlin")
assertTrue(stringBuilder contentEquals "Kotlin")

stringBuilder.setCharAt(0, 'k')
assertPrints(stringBuilder, "kotlin")
assertFalse("Kotlin".contentEquals(stringBuilder))
assertTrue("Kotlin".contentEquals(stringBuilder, ignoreCase = true)) 
   //sampleEnd
}

Parameters

ignoreCase

true to ignore character case when comparing contents.

actual infix fun CharSequence?.contentEquals(other: CharSequence?): Boolean

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 samples.*
import java.util.Locale
import kotlin.test.*
fun main() { 
   //sampleStart 
   val stringBuilder = StringBuilder()
stringBuilder.append("Kot").append("lin")
assertPrints(stringBuilder, "Kotlin")
assertTrue(stringBuilder contentEquals "Kotlin")

stringBuilder.setCharAt(0, 'k')
assertPrints(stringBuilder, "kotlin")
assertFalse("Kotlin".contentEquals(stringBuilder))
assertTrue("Kotlin".contentEquals(stringBuilder, ignoreCase = true)) 
   //sampleEnd
}

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

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

Samples

import samples.*
import java.util.Locale
import kotlin.test.*
fun main() { 
   //sampleStart 
   val stringBuilder = StringBuilder()
stringBuilder.append("Kot").append("lin")
assertPrints(stringBuilder, "Kotlin")
assertTrue(stringBuilder contentEquals "Kotlin")

stringBuilder.setCharAt(0, 'k')
assertPrints(stringBuilder, "kotlin")
assertFalse("Kotlin".contentEquals(stringBuilder))
assertTrue("Kotlin".contentEquals(stringBuilder, ignoreCase = true)) 
   //sampleEnd
}

Parameters

ignoreCase

true to ignore character case when comparing contents.

actual infix fun CharSequence?.contentEquals(other: CharSequence?): Boolean

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 samples.*
import java.util.Locale
import kotlin.test.*
fun main() { 
   //sampleStart 
   val stringBuilder = StringBuilder()
stringBuilder.append("Kot").append("lin")
assertPrints(stringBuilder, "Kotlin")
assertTrue(stringBuilder contentEquals "Kotlin")

stringBuilder.setCharAt(0, 'k')
assertPrints(stringBuilder, "kotlin")
assertFalse("Kotlin".contentEquals(stringBuilder))
assertTrue("Kotlin".contentEquals(stringBuilder, ignoreCase = true)) 
   //sampleEnd
}

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

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

Samples

import samples.*
import java.util.Locale
import kotlin.test.*
fun main() { 
   //sampleStart 
   val stringBuilder = StringBuilder()
stringBuilder.append("Kot").append("lin")
assertPrints(stringBuilder, "Kotlin")
assertTrue(stringBuilder contentEquals "Kotlin")

stringBuilder.setCharAt(0, 'k')
assertPrints(stringBuilder, "kotlin")
assertFalse("Kotlin".contentEquals(stringBuilder))
assertTrue("Kotlin".contentEquals(stringBuilder, ignoreCase = true)) 
   //sampleEnd
}

Parameters

ignoreCase

true to ignore character case when comparing contents.