String’s endWith method checks if String ends with specific suffix. It returns boolean datatype.
Method syntax:
public boolean endsWith(String suffix)
String endsWith Example:
package org.arpit.java2blog;
public class StringEndsWithExample {
public static void main(String[] args) {
String str = "java2blog";
if (str.endsWith("blog")) {
System.out.println("String ends with blog");
}
else {
System.out.println("String does not end with blog");
}
if (str.endsWith("BLOG")) {
System.out.println("String ends with BLOG");
}
else {
System.out.println("String does not end with BLOG");
}
}
}
When you run above program, you will get below output:
String ends with blog String does not end with BLOG
Please note that endsWith method is case sensitive as you can see in above example