Home > Back-end >  What is Diff between "contains" and "in" (Kotlin)
What is Diff between "contains" and "in" (Kotlin)

Time:03-31

fun main() {
    val input = "ABC"
    val output = "ABC,"
    println(input.contains(output,false))
    print(input in (output))
}

Output :

false 
true

I just checked that, in and contains are using same method, but why giving difference results.

CodePudding user response:

The Kotlin contains function

Returns true if this char sequence contains the specified other sequence of characters as a substring.

Actually, you're checking if input.contains(output), and "ABC" does not contain "ABC,".

The correct syntax is

println(output.contains(input,false))
  • Related