
一个字符串是一个表示不可变字符序列的对象,一旦创建就不能更改。可以使用 java.lang.String类来创建字符串对象。
我们可以使用String 类的endsWith()方法来检查一个字符串是否以特定字符串结尾,它返回一个布尔值true 或false。
public boolean endsWith(String prefix)
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!
以上就是在Java中如何检查字符串是否以特定子字符串结尾?的详细内容,更多请关注php中文网其它相关文章!
java怎么学习?java怎么入门?java在哪学?java怎么学才快?不用担心,这里为大家提供了java速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号