java endswith函数怎么用

   2025-02-15 5000
核心提示:Java的endsWith()函数用于判断字符串是否以指定的后缀结束。它的用法如下:String str = Hello, World!;// 判断字符串是否以指定

Java的endsWith()函数用于判断字符串是否以指定的后缀结束。它的用法如下:

String str = "Hello, World!";// 判断字符串是否以指定的后缀结束boolean endsWithExclamation = str.endsWith("!"); // trueboolean endsWithComma = str.endsWith(","); // falseSystem.out.println(endsWithExclamation);System.out.println(endsWithComma);

在上面的例子中,endsWith()函数分别判断字符串str是否以感叹号!或逗号,结束。结果表明字符串str以感叹号!结束(为true),但不以逗号,结束(为false)。

 
 
更多>同类维修知识
推荐图文
推荐维修知识
点击排行
网站首页  |  关于我们  |  联系方式  |  用户协议  |  隐私政策  |  网站留言