English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Java Basic Tutorial

Java flow control

Java array

Java object-oriented (I)

Java object-oriented (II)

Java object-oriented (III)

Java Exception Handling

Java List

Java Queue (queue)

Java Map collection

Java Set collection

Java input/output (I/O)/O)

Java Reader/Writer

Java other topics

Java String endsWith() usage and example

Java String (String) Methods

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.

EndsWith() parameters

  • str - Check if the string ends with str

EndsWith() return value

  • If the string ends with the given stringReturns true

  • If the string does not end with the given stringReturns false

Example: Java endWith() without offset parameter

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.

Java String (String) Methods