logo

Java String ContentEquals() Method


Show

Description

This technique revisits true if and only if this String depicts the similar sequence of values as particular in StringBuffer. The process contentEquals() distinguishes the String with the String Buffer and revisits a boolean value. It revisits true if the String competitions to the String buffer else it returns false.

Syntax

Here is the syntax of this method:

public boolean contentEquals(StringBuffer sb)

Parameters

Here is the detail of parameters −

  • sb − the StringBuffer to compare.

Return Value

  • This method returns true if and only if this String represents the same sequence of characters as the specified in StringBuffer, otherwise false.

Example

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);
   }
}

This will produce the following result:

Output

true
false

Here at Intellinuts, we have created a complete Java tutorial for Beginners to get started in Java.