Please note, this is a STATIC archive of website www.w3schools.com from 05 May 2020, cach3.com does not collect or store any user information, there is no "phishing" involved.
THE WORLD'S LARGEST WEB DEVELOPER SITE

Java String endsWith() Method

❮ String Methods


Example

Find out if the string ends with the specified characters:

public class MyClass {
  public static void main(String[] args) {
    String myStr = "Hello";
    System.out.println(myStr.endsWith("Hel"));   // false
    System.out.println(myStr.endsWith("llo"));   // true
    System.out.println(myStr.endsWith("o"));     // true
  }
}

Run example »


Definition and Usage

The endsWith() method checks whether a string ends with the specified character(s).

Tip: Use the startsWith() method to check whether a string starts with the specified character(s).


Syntax

public boolean endsWith(String chars)

Parameter Values

Parameter Description
chars A String, representing the character(s) to check for

Technical Details

Returns: A boolean value:
  • true - if the string ends with the specified character(s)
  • false - if the string does not end with the specified character(s)

❮ String Methods