.endsWith()
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