The contains() Function is used to find a substring from the String.
fun main() { var x = "Beautiful" var y = x.contains("tif") if (y == true) { println("The substring tif is present in the String") } else { println("The substring tif is not present in the String") } }
In the above code, we have declared a String 'Beautiful' and assigned it to a variable 'x'.
And we would be searching the substring 'tif', from the String, 'Beautiful'.
So, we have used the 'contains()' Function to find if the substring 'tif' is present in the String, 'Beautiful'.
And what 'contains()' Function does is, goes to the String 'Beautiful' and searches if the substring 'tif' is present in it or not.
And finds the substring substring 'tif' is present.
And the below output is printed.