×

Scala Tutorial

Scala Basics

Scala Control statements

Scala Functions

Scala Arrays

Scala Lists

Scala Strings

Scala Classes & Objects

Scala Collections

Scala String endsWith() Method

By IncludeHelp Last updated : October 21, 2024

Description and Usage

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!

Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.