Languages
[Edit]
EN

Java - string endsWith() method example

0 points
Created by:
TheDalot
390

In this article, we would like to show you endsWith() method example in Java.

Quick solution:

String string = "Dirask is awesome";

System.out.println(string.endsWith("awesome"));  // true
System.out.println(string.endsWith("is"));       // false

 

1. Documentation

Syntaxpublic boolean endsWith(String suffix)
Parameterssuffix - the string representation of the character to be checked
Resulttrue - if the string ends with the specified character or word,
false - if the string doesn't end with the specified character or word.
Description

Tests if the string ends with the specified suffix.

2. Practical example

In this example, we check if our string ends with a specified character or string.

public class Example {
    public static void main(String[] args) {
        String string = "Dirask is awesome";

        System.out.println(string.endsWith("e"));         // true
        System.out.println(string.endsWith("awesome"));   // true

        System.out.println(string.endsWith("i"));         // false
        System.out.println(string.endsWith("is"));        // false
    }
}

Output:

true
true
false
false
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.

Java - String documentation

Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join