.endsWith()
Anonymous contributor
Anonymous contributor5 total contributions
Anonymous contributor
Published Oct 27, 2023
Contribute to Docs
The .endsWith()
method compares the end of the sequence with the given suffix and returns a boolean value indicating whether they are the same or not.
Syntax
String.endsWith(suffix, ignoreCase)
String
: The sequence which the suffix is to be compared with.suffix
: A sequence of lengthn
, to be compared with the lastn
elements ofString
.ignoreCase
: A boolean value dictating whether function is to be case insensitive. Defaults to false.
Example
The example demonstrates the use of .endsWith()
to compare the end of a sequence, first to the string “@gmail.com”, then with the string “@hotmail.com”.
fun main() {val sfx1 = "@gmail.com"val sfx2 = "@hotmail.com"val endsWithSfx1 = str.endsWith(sfx1)println(endsWithSfx1)val endsWithSfx2 = str.endsWith(sfx2, true)println(endsWithSfx2)}
The output of this code will be:
falsetrue
All contributors
- Anonymous contributorAnonymous contributor5 total contributions
- Anonymous contributor
Looking to contribute?
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.