EN
Java - string endsWith() method example
0 points
In this article, we would like to show you endsWith()
method example in Java.
Quick solution:
xxxxxxxxxx
1
String string = "Dirask is awesome";
2
3
System.out.println(string.endsWith("awesome")); // true
4
System.out.println(string.endsWith("is")); // false
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. |
In this example, we check if our string
ends with a specified character or string.
xxxxxxxxxx
1
public class Example {
2
public static void main(String[] args) {
3
String string = "Dirask is awesome";
4
5
System.out.println(string.endsWith("e")); // true
6
System.out.println(string.endsWith("awesome")); // true
7
8
System.out.println(string.endsWith("i")); // false
9
System.out.println(string.endsWith("is")); // false
10
}
11
}
Output:
xxxxxxxxxx
1
true
2
true
3
false
4
false