Java-string-equalsignorecase

提供:Dev Guides
移動先:案内検索

Java-String equalsIgnoreCase()メソッド

説明

このメソッドは、大文字と小文字の考慮を無視して、この文字列を別の文字列と比較します。 2つの文字列は、同じ長さである場合、大文字と小文字を区別せずに等しいと見なされ、2つの文字列の対応する文字は大文字と小文字を区別せずに等しくなります。

構文

このメソッドの構文は次のとおりです-

public boolean equalsIgnoreCase(String anotherString)

パラメーター

ここにパラメータの詳細があります-

  • anotherString -この文字列と比較する文字列。

戻り値

  • 引数がnullでなく、文字列が等しい場合、このメソッドはtrueを返し、大文字と小文字を区別しません。それ以外の場合はfalse。

public class Test {

   public static void main(String args[]) {
      String Str1 = new String("This is really not immutable!!");
      String Str2 = Str1;
      String Str3 = new String("This is really not immutable!!");
      String Str4 = new String("This IS REALLY NOT IMMUTABLE!!");
      boolean retVal;

      retVal = Str1.equals( Str2 );
      System.out.println("Returned Value = " + retVal );

      retVal = Str1.equals( Str3 );
      System.out.println("Returned Value = " + retVal );

      retVal = Str1.equalsIgnoreCase( Str4 );
      System.out.println("Returned Value = " + retVal );
   }
}

これは、次の結果を生成します-

出力

Returned Value = true
Returned Value = true
Returned Value = true