What is Diff between "contains" and "in" (Kotlin)

933 Views Asked by At
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.

1

There are 1 best solutions below

1
On BEST ANSWER

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))