共计 358 个字符,预计需要花费 1 分钟才能阅读完成。
Java 的 endsWith()函数用于判断字符串是否以指定的后缀结束。它的用法如下:
String str = "Hello, World!";
// 判断字符串是否以指定的后缀结束
boolean endsWithExclamation = str.endsWith("!"); // true
boolean endsWithComma = str.endsWith(","); // false
System.out.println(endsWithExclamation);
System.out.println(endsWithComma);
在上面的例子中,endsWith()函数分别判断字符串 str 是否以感叹号 ! 或逗号 , 结束。结果表明字符串 str 以感叹号 ! 结束(为 true),但不以逗号 , 结束(为 false)。
丸趣 TV 网 – 提供最优质的资源集合!
正文完