Java String endsWith() 方法
示例
判斷字串是否以指定字元結束
String myStr = "Hello";
System.out.println(myStr.endsWith("Hel")); // false
System.out.println(myStr.endsWith("llo")); // true
System.out.println(myStr.endsWith("o")); // true
定義和用法
endsWith()
方法檢查字串是否以指定字元或字元序列結束。
提示:使用 startsWith() 方法檢查字串是否以指定字元或字元序列開頭。
語法
public boolean endsWith(String chars)
引數值
引數 | 描述 |
---|---|
chars | 一個 String ,表示要檢查的字元或字元序列 |
技術詳情
返回 | 一個 boolean 值
|
---|
❮ String Methods