EN
Java - string endsWith() method example
0
points
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
Syntax | public boolean endsWith(String suffix) |
Parameters | suffix - the string representation of the character to be checked |
Result | true - 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