The endsWith
function in Scala checks whether a particular string ends with the element stated as a parameter. It takes a single parameter: a string
element. It then returns true if the given string ends with the element stated and false otherwise.
The illustration below shows how the endsWith
function works in Scala:
The endsWith
function takes in a single parameter: a string
element.
The endsWith
function returns true
if the given string ends with the element stated in the parameter. Otherwise, it returns false
.
The code snippet below shows how the endsWith
function works in Scala:
object Compare {def main(args: Array[String]) {val myString = "Educative";val result = myString.endsWith("e");val result2 = myString.endsWith("v");println("With e: " + result);println("With v: " + result2);}}
As the output shows, the function:
string
“Educative” ends with an “e”.string
“Educative” does not end with a “v”.RELATED TAGS
CONTRIBUTOR