endsWith() Java - check whether a string ends with a specified suffix

Facebooktwittergoogle_plustumblrFacebooktwittergoogle_plustumblr

The endsWith() method checks whether a string ends with a specified suffix, value, etc.

Syntax:

How To Call the Method:

Example:

If you run this code on your computer, you will see the following in the console:

Commentary:

There is a string "Good morning"

  • With the help of endsWith() we checked whether the string ends with "morning". Yes, it ends with "morning", that's why we've got "true" in the console.
  • With the help of endsWith() we checked whether the sting ends with "evening". No, it doesn't end with evening, that's why we've got "false" in the console.

Please note, that if we add any character, for example an exclamation mark after the word "morning", then we'll get "false" in the console.

That's it for this article. You can find more articles in our Java Tutorial for Beginners. 

Facebooktwittergoogle_plustumblrFacebooktwittergoogle_plustumblr

Facebooktwittergoogle_plustumblrFacebooktwittergoogle_plustumblr
Самоучители--узнать детальнее--