一个字符串是一个表示不可变字符序列的对象,一旦创建就不能更改。可以使用 java.lang.string类来创建字符串对象。
我们可以使用string 类的endswith()方法来检查一个字符串是否以特定字符串结尾,它返回一个布尔值true 或false。
语法public boolean endswith(string prefix)
examplepublic 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中如何检查字符串是否以特定子字符串结尾?的详细内容。