ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT

Scala String endsWith() Method with Example

Here, we will learn about the endsWith() method of String class in Scala. It is used to check for the presence of suffix substring in the string. We will see its working, syntax and example.
Submitted by Shivang Yadav, on February 04, 2021

String is an immutable collection that stores sequences of characters.

String endsWith() Method

The endsWith() method on strings is used to check whether the string ends with the given suffix substring passed as parameter to the method.

Syntax:

string_Name.endsWith(String subString)

Parameters: The method accepts a single parameter which the suffix substring to be checked in the string.

Return Value: It returns a Boolean value which is the result of the comparison operation.

Example 1:

object myObject {
    def main(args: Array[String]) {
        val myString = "Scala programming language"
        
        val isSuffixPresnt = myString.endsWith("language")
    
        if(isSuffixPresnt)
            println("The string ends with the given suffix!")
        else 
            println("The string does not end with the given suffix!")
    }
}

Output:

The string ends with the given suffix!

Example 2:

object myObject {
    def main(args: Array[String]) {
        val myString = "Scala programming language"
        
        val isSuffixPresnt = myString.endsWith("f")
    
        if(isSuffixPresnt)
            println("The strings ends with the given suffix!")
        else 
            println("The strings does not end with the given suffix!")
    }
}

Output:

The strings does not end with the given suffix!
ADVERTISEMENT



ADVERTISEMENT



Comments and Discussions

ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.