📅  最后修改于: 2020-09-26 03:04:31             🧑  作者: Mango
java 字符串 endsWith()方法检查此字符串是否以给定的后缀结尾。如果此字符串以给定的后缀结尾,则返回true,否则返回false。
" public boolean endsWith(String suffix) {
return startsWith(suffix, value.length - suffix.value.length);
}
下面给出了endsWith()方法的语法或签名。
"public boolean endsWith(String suffix)
后缀:字符序列
True or False
"public class EndsWithExample{
public static void main(String args[]){
String s1="java by javatpoint";
System.out.println(s1.endsWith("t"));
System.out.println(s1.endsWith("point"));
}}
输出:
"true
true
"public class EndsWithExample2 {
public static void main(String[] args) {
String str = "Welcome to Javatpoint.com";
System.out.println(str.endsWith("point"));
if(str.endsWith(".com")) {
System.out.println("String ends with .com");
}else System.out.println("It does not end with .com");
}
}
输出:
"false
String ends with .com