Open In App

Scala String endsWith() method with example

The endsWith() method is utilized to check if the stated string ends with the suffix stated in the argument.

Method Definition: Boolean endsWith(String suffix)
Return Type: It returns true if the string ends with the suffix stated else it returns false.



Example #1:




// Scala program of endsWith()
// method
  
// Creating object
object GfG
  
    // Main method
    def main(args:Array[String])
    {
        // Creating a String
        val m1= "Nidhi"
          
        // Applying endsWith() method
        val result = m1.endsWith("i")
          
        // Displays output
        println(result)
      
    }

Output:
true

Example #2:




// Scala program of endsWith()
// method
  
// Creating object
object GfG
  
    // Main method
    def main(args:Array[String])
    {
        // Creating a String
        val m1= "Nidhi"
          
        // Applying endsWith() method
        val result = m1.endsWith("y")
          
        // Displays output
        println(result)
      
    }

Output:

false

Article Tags :