Java endsWith()方法,判断字符串结尾

Java endsWith()方法

Java中String类的方法endsWith()可以用于判断调用对象——字符串是否以参数指定的子串结尾,对大小写敏感。endsWith()语法如下:

boolean endsWith(String str)

endsWith()参数

参数描述
strString类型字符串

endsWith()返回值

boolean类型值:

返回值描述
true字符串是以参数指定的子串结尾
false与上面的相反

endsWith()实例代码

public class test {
    public static void main(String[] args) {
        String x = "笨鸟工具,x1y1z1.com";
        boolean y = x.endsWith("com");
        System.out.println("y= "+y);

    }

}

代码运行后,得到输出值为:

y=true

免责声明:内容仅供参考,不保证正确性。


全栈后端 / Java教程 :









Copyright © 2022-2024 笨鸟工具 x1y1z1.com All Rights Reserved.