Java String endsWith() Method Tutorial

In this section, we will learn what the String endsWith() method is and how to use it in Java.

What is Java String endsWith() Method?

The Java String endsWith() method is used to check a string value and see if that string ends with a specific character sequence or not.

Java endsWith() Method Syntax:

public boolean endsWith(String chars)

endsWith() Method Parameters:

The `endsWith()` method takes a String value as its argument and checks to see if the target String object ends with the value of the argument we set in the method.

endsWith() Method Return Value:

The return value of this method is a boolean value:

If the target String object ends with the String value that we set as the argument to the method, the result will be true otherwise it is false.

Example: using String endsWith() method

public class Simple {

    public static void main(String[] args) {
        String message = "Be kind to one another";
        System.out.println(message.endsWith("another"));
        System.out.println(message.endsWith("one another"));
        System.out.println(message.endsWith("the another"));
    }
}

Output:

true

true

false

Facebook
Twitter
Pinterest
LinkedIn

Top Technologies