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 :



package main
import "fmt"
import "strings"
    
func main() {
    
    x := "Beautiful"
    y := strings.Contains(x, "tif")
            
    if (y == true) { 
        fmt.Println("The substring tif is present in the String")  
    } else {
        fmt.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'.


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


y := strings.Contains(x, "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