Open In App

Scala String endsWith() method with example

Last Updated : 03 Oct, 2019
Improve
Improve
Like Article
Like
Save
Share
Report

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


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads