endsWith() String Example

endsWith() String Example


Java String class comes with many string utility methods with which string manipulation becomes easier. Read these methods and you will remember the laborious days of C/C++. One such method is endsWith() String.

The present method endsWith(String str) checks the given string ends with a few characters like str or not. If ends with characters str, the method returns true else false.

The signature is given as defined in String class.

  • public boolean endsWith(String str): Returns true if the given string ends with str, else false.

Following example on endsWith() String illustrates the usage of both the above methods.


endsWith() String
Output screenshot on endsWith() String Example

A similar method exists in String class startsWith() String.

Leave a Reply

Your email address will not be published. Required fields are marked *