Easy Tutorial
❮ Java Stringbuffer Number Tostring ❯

Java contentEquals() Method

Java String Class


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

Syntax

public boolean contentEquals(StringBuffer sb)

Parameters

Return Value

Returns true if the string and the specified StringBuffer represent the same character sequence; 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 output of the above program is:

true
false

Java String Class

❮ Java Stringbuffer Number Tostring ❯