Skip to content
Related Articles

Related Articles

Scala String endsWith() method with example
  • Last Updated : 03 Oct, 2019

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



My Personal Notes arrow_drop_up
Recommended Articles
Page :