English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
The Java String startsWith() method checks if the string ends with the specified string.
The syntax of the string endsWith() method is:
string.endsWith(String str)
Here, string is an object of the String class.
str - Check if the string ends with str
If the string ends with the given stringReturns true
If the string does not end with the given stringReturns false
class Main { public static void main(String[] args) { String str = "Java Programming"; System.out.println(str.endsWith("mming")); // true System.out.println(str.endsWith("g")); // true System.out.println(str.endsWith("a Programming")); // true System.out.println(str.endsWith("programming")); // false System.out.println(str.endsWith("Java")); // false } }
From the above examples, it can be seen that endsWith() is case-sensitive (lowercase and uppercase).
If you need to check if a string starts with a specified string, please useJava String startsWith()Method.