Linux 拨号vps windows公众号手机端

java endswith函数怎么用

lewis 8年前 (2017-10-15) 阅读数 11 #程序编程
文章标签 Java

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)。

版权声明

本文仅代表作者观点,不代表米安网络立场。

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

热门