Groovy - equalsIgnoreCase()



比較該字串和另一個字串時,忽略大小寫區別。

語法

Boolean equalsIgnoreCase(String str)

引數

  • Str - 要在此字串上比較的字串

返回值

如果引數不為空且字串相等,忽略大小寫,則此方法返回 true;否則返回 false。

示例

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

class Example { 
   static void main(String[] args) { 
      String a = "Hello World"; 
      String b = "HELLO World"; 
      String c = "HELLO WORLD";
		
      println(a.equalsIgnoreCase(b)); 
      println(a.equalsIgnoreCase(c)); 
      println(b.equalsIgnoreCase(c)); 
   } 
}

當我們執行以上程式時,將獲得以下結果 −

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