共計 358 個字符,預(yù)計需要花費 1 分鐘才能閱讀完成。
Java 的 endsWith()函數(shù)用于判斷字符串是否以指定的后綴結(jié)束。它的用法如下:
String str = "Hello, World!";
// 判斷字符串是否以指定的后綴結(jié)束
boolean endsWithExclamation = str.endsWith("!"); // true
boolean endsWithComma = str.endsWith(","); // false
System.out.println(endsWithExclamation);
System.out.println(endsWithComma);
在上面的例子中,endsWith()函數(shù)分別判斷字符串 str 是否以感嘆號 ! 或逗號 , 結(jié)束。結(jié)果表明字符串 str 以感嘆號 ! 結(jié)束(為 true),但不以逗號 , 結(jié)束(為 false)。
丸趣 TV 網(wǎng) – 提供最優(yōu)質(zhì)的資源集合!
正文完