Easy Tutorial
❮ String Split Character Isdigit ❯

Java endsWith() Method

Java String Class


The endsWith() method is used to test whether the string ends with the specified suffix.

Syntax

public boolean endsWith(String suffix)

Parameters

Return Value

Returns true if the character sequence represented by the argument is a suffix of the character sequence represented by this object; otherwise returns false. Note that the result is true if the argument is an empty string, or is equal to this String object as determined by the equals(Object) method.

Example

public class Test {
    public static void main(String args[]) {
        String Str = new String("tutorialpro.org:www.tutorialpro.org");
        boolean retVal;

        retVal = Str.endsWith("tutorialpro");
        System.out.println("Return Value = " + retVal);

        retVal = Str.endsWith("com");
        System.out.println("Return Value = " + retVal);
    }
}

The above program execution results are:

Return Value = false
Return Value = true

Java String Class

❮ String Split Character Isdigit ❯