Java-string-contentequals
提供:Dev Guides
Java-String contentEquals()メソッド
説明
このメソッドは、この文字列がStringBufferで指定されたのと同じ文字シーケンスを表す場合にのみtrueを返します。
構文
このメソッドの構文は次のとおりです-
public boolean contentEquals(StringBuffer sb)
パラメーター
ここにパラメータの詳細があります-
- sb -比較するStringBuffer。
戻り値
- このメソッドは、この文字列がStringBufferで指定されたのと同じ文字シーケンスを表す場合にのみtrueを返し、そうでない場合はfalseを返します。
例
public class Test {
public static void main(String args[]) {
String str1 = "Not immutable";
String str2 = "Strings are immutable";
StringBuffer str3 = new StringBuffer( "Not immutable");
boolean result = str1.contentEquals( str3 );
System.out.println(result);
result = str2.contentEquals( str3 );
System.out.println(result);
}
}
これは、次の結果を生成します-
出力
true
false