Java contentEquals() Method

Java String类Java String Class


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

Syntax

public boolean contentEquals(StringBuffer sb)

Parameters

  • sb-- The StringBuffer to be compared with the string.

Return Value

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

Examples

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类Java String Class

Other Extensions