endsWith() method is a string class method in Java.
This is a simple endswith() java example, that check if the assigned string
ends with the given string or not. If the given string does not ends with the
given specific string(suffix) it will return False otherwise True.
Syntax of endsWith() method in Java
boolean endsWith(String suffix)
A simple Examples:
public class Example
{
public static void main(String[] args)
{
String str1 = "Java Programming Language";
String str2 = "Java application programming";
// will check if the given string ends with "ng" or not
String strendswith = "ng";
// checking the condition
boolean ends1 = str1.endsWith(strendswith);
boolean ends2 = str2.endsWith(strendswith);
// display the output
System.out.println("\"" + str1 + "\" ends with " +
"\"" + strendswith + "\"? " + ends1);
System.out.println("\"" + str2 + "\" ends with " +
"\"" + strendswith + "\"? " + ends2);
}
}
the Output is:
"Java Programming Language" ends with "ng"? false
"Java application programming" ends with "ng"? true