Javaは()メソッドに等しいです
等号()メソッドは、指定されたオブジェクトに文字列を比較するために使用されます。
文法
public boolean equals(Object anObject)
パラメータ
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"); boolean retVal; retVal = Str1.equals( Str2 ); System.out.println("返回值 = " + retVal ); retVal = Str1.equals( Str3 ); System.out.println("返回值 = " + retVal ); } }
上記プログラムの実行結果:
返回值 = true 返回值 = true