溫馨提示×

java endswith函數(shù)怎么用

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

Java的endsWith()函數(shù)用于判斷字符串是否以指定的后綴結束。它的用法如下:

String str = "Hello, World!";

// 判斷字符串是否以指定的后綴結束
boolean endsWithExclamation = str.endsWith("!"); // true
boolean endsWithComma = str.endsWith(","); // false

System.out.println(endsWithExclamation);
System.out.println(endsWithComma);

在上面的例子中,endsWith()函數(shù)分別判斷字符串str是否以感嘆號!或逗號,結束。結果表明字符串str以感嘆號!結束(為true),但不以逗號,結束(為false)。

0