![]() |
VOOZH | about |
In Java, the endsWith() method of the String class is used to check if a string ends with a specific suffix. The endsWith() method is present in the java.lang package. In this article, we will learn how to use the endsWith() method in Java and explore its practical examples.
Example:
In this example, we will use the endsWith() method to check whether the string ends with a specific suffix.
true
Table of Content
boolean endsWith(String suffix)
Parameter:
Return Type:
The endsWith() method is case-sensitive. This means that it will return false if the case of the characters does not match the specified suffix.
Example:
false
We can also check whether the string ends with any suffix.
Example:
true
endsWith() with an Empty StringWe can check if a string ends with an empty string or not. It will always return true, because every string ends with an empty string.
Example:
true
endsWith() for File ExtensionsThe endsWith() method used for checking file extensions. We can check if a file name ends with .txt or anything else.
Example:
true
We can also check if a string ends with a space using the endsWith() method.
Example:
false