「Java」contentEqualsメソッドで指定StringBufferを比較するサンプル

説明
public boolean contentEquals(StringBuffer sb)
この文字列と指定された StringBuffer を比較します。
使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
package com.study.arkgame;
public class ContentDemo {
public static void main(String[] args) {
String targetA = "study skill";
String targetB = "this is a test";
StringBuffer targetC = new StringBuffer("study skill");
boolean result = targetA.contentEquals(targetC);
System.out.println("比較結果1: " + result);
result = targetB.contentEquals(targetC);
System.out.println("比較結果2: " + result);
}
}
package com.study.arkgame; public class ContentDemo { public static void main(String[] args) { String targetA = "study skill"; String targetB = "this is a test"; StringBuffer targetC = new StringBuffer("study skill"); boolean result = targetA.contentEquals(targetC); System.out.println("比較結果1: " + result); result = targetB.contentEquals(targetC); System.out.println("比較結果2: " + result); } }
package com.study.arkgame;

public class ContentDemo {

      public static void main(String[] args) {
            String targetA = "study skill";
            String targetB = "this is a test";
            StringBuffer targetC = new StringBuffer("study skill");

            boolean result = targetA.contentEquals(targetC);
            System.out.println("比較結果1: " + result);

            result = targetB.contentEquals(targetC);
            System.out.println("比較結果2: " + result);
      }

}

実行結果
比較結果1: true
比較結果2: false

Java

Posted by arkgame