溫馨提示×

java endswith函數怎么用

小億
263
2023-11-10 09:16:23
欄目: 編程語言

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

0
亚洲午夜精品一区二区_中文无码日韩欧免_久久香蕉精品视频_欧美主播一区二区三区美女