Java文字列equals()メソッド
例
文字列を比較して、それらが等しいかどうかを確認します。
String myStr1 = "Hello";
String myStr2 = "Hello";
String myStr3 = "Another String";
System.out.println(myStr1.equals(myStr2)); // Returns true because they are equal
System.out.println(myStr1.equals(myStr3)); // false
定義と使用法
このequals()
メソッドは2つの文字列を比較し、文字列が等しい場合はtrueを返し、等しくない場合はfalseを返します。
ヒント:compareTo()メソッドを使用して、2つの文字列を辞書式に比較します。
構文
public boolean equals(Object anotherObject)
パラメータ値
Parameter | Description |
---|---|
anotherObject | An Object , representing the other string
to be compared |
技術的な詳細
戻り値: | boolean 値
:
|
---|---|
オーバーライド: | equals クラスでObject |
❮文字列メソッド