Groovy - endsWith()



測試此字串是否以指定字尾結尾。

語法

Boolean endsWith(String suffix)

引數

  • 字尾 - 要搜尋的字尾

返回值

此方法在以下情況下返回 true:由引數表示的字元序列是由此物件表示的字元序列的字尾;否則返回 false。請注意,如果引數是空字串或根據 equals(Object) 方法確定等於此字串物件,結果將為 true。

示例

以下是使用此方法的一個示例 -

class Example {
   static void main(String[] args) {
      String s = "HelloWorld";
		
      println(s.endsWith("ld"));
      println(s.endsWith("lo"));
      println("Hello".endsWith("lo"));
   } 
} 

執行以上程式時,我們將得到以下結果 -

true
false 
true 
groovy_strings.htm
廣告
© . All rights reserved.