Learnerslesson
   JAVA   
  SPRING  
  SPRINGBOOT  
 HIBERNATE 
  HADOOP  
   HIVE   
   ALGORITHMS   
   PYTHON   
   GO   
   KOTLIN   
   C#   
   RUBY   
   C++   




contains() FUNCTION


contains() Function


The contains() Function is used to find a substring from the String.


Example :



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


Output :



 The substring tif is present in the String

In the above code, we have declared a String 'Beautiful' and assigned it to a variable 'x'.


var x = "Beautiful"

java_Collections

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


var y = x.contains("tif")

And what 'contains()' Function does is, goes to the String 'Beautiful' and searches if the substring 'tif' is present in it or not.


java_Collections

And finds the substring substring 'tif' is present.


And the below output is printed.


The substring tif is present in the String