JavaのequalsIgnoreCase()メソッド
equalsIgnoreCase()メソッドは、ケースに関係なく、指定されたオブジェクトに文字列を比較するために使用されます。
文法
public boolean equalsIgnoreCase(String anotherString)
パラメータ
anObject -文字列を比較するオブジェクト。
戻り値
文字列が指定されたオブジェクトと等しい場合は、trueを返し、そうでない場合はfalse。
例
public class Test { public static void main(String args[]) { String Str1 = new String("w3big"); String Str2 = Str1; String Str3 = new String("w3big"); String Str4 = new String("w3big"); boolean retVal; retVal = Str1.equals( Str2 ); System.out.println("返回值 = " + retVal ); retVal = Str3.equals( Str4); System.out.println("返回值 = " + retVal ); retVal = Str1.equalsIgnoreCase( Str4 ); System.out.println("返回值 = " + retVal ); } }
上記プログラムの実行結果:
返回值 = true 返回值 = false 返回值 = true