.endsWith()
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 contributor
Contribute to Docs
- 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.
Learn Kotlin on Codecademy
- Career path
Computer Science
Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!Includes 6 CoursesWith Professional CertificationBeginner Friendly75 hours - Free course
Learn Kotlin
Learn Kotlin, the expressive, open-source programming language developed by JetBrains.Beginner Friendly9 hours