
一个字符串是一个表示不可变字符序列的对象,一旦创建就不能更改。可以使用 java.lang.String类来创建字符串对象。
我们可以使用String 类的endsWith()方法来检查一个字符串是否以特定字符串结尾,它返回一个布尔值true 或false。
语法
public boolean endsWith(String prefix)
Example
public class StringEndsWithSubStringTest {
public static void main(String[] args) {
String str = "WelcomeToTutorialsPoint";
if(str.endsWith("Point")) {
System.out.println("Ends with the specified word!");
} else {
System.out.println("Does not end with the specified word!");
}
}
}输出
Ends with the specified word!











