string ends with check code example
Example 1: how to check the end of a string java
public class Demo {
public static void main(String[] args) {
String str = "demo";
if(str.endsWith("mo")) {
System.out.println("The string ends with the word mo");
} else {
System.out.println("The string does not end with the word mo");
}
}
}
Example 2: how to compare a string with its ending in javascript
function solution(str, ending){
return str.indexOf(ending, str.length - ending.length) !== -1;
}