📜  java-string-endswith

📅  最后修改于: 2020-09-26 03:04:31             🧑  作者: Mango

Java字符串endsWith()

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

Java字符串endsWith()方法示例

"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

Java字符串endsWith()方法示例2

"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