.endsWith()
Published Feb 16, 2023
Contribute to Docs
The .endsWith()
method returns true
if a string ends with a given suffix, otherwise false
.
Syntax
str.endsWith(String suffix)
suffix
(required): The characters to be matched in the string.
Example
The example below demonstrates the use of the .endsWith()
method:
// Example.javaclass Example {public static void main(String args[]) {String domain = "codecademy.com";// Output will be true as "codecademy.com" ends in "com"boolean bool = domain.endsWith("com");System.out.println(bool);}}
This outputs the following:
true
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 Java 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 Java
Learn to code in Java — a robust programming language used to create software, web and mobile apps, and more.Beginner Friendly16 hours