Kotlin .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 lastnelements 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
- Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
- Includes 6 Courses
- With Professional Certification
- Beginner Friendly.75 hours
- Learn Kotlin, the expressive, open-source programming language developed by JetBrains.
- Beginner Friendly.9 hours