java endswith函数怎么用

1357
2023/11/7 9:16:23
栏目: 编程语言
开发者测试专用服务器限时活动,0元免费领,库存有限,领完即止! 点击查看>>

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

辰迅云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>

推荐阅读: java怎么去除字符串中的重复字符