Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Java contentEquals() Method

Java contentEquals() Method

Java String ClassJava String class


The contentEquals() method is used to compare this string with the specified StringBuffer.

Syntax


public boolean contentEquals(StringBuffer sb)

Parameters

Return Value

Returns true if the string represents the same sequence of characters as the specified StringBuffer; otherwise returns false.

Example


public class Test {
    public static void main(String args[]) {
        String str1 = "String1";
        String str2 = "String2";
        StringBuffer str3 = new StringBuffer( "String1");

        boolean  result = str1.contentEquals( str3 );
        System.out.println(result);
          
        result = str2.contentEquals( str3 );
        System.out.println(result);
    }
}

The execution result of the above program is:


true
false

Java String ClassJava String class