Program
public class StringContentEqualsStringBuffer { public static void main(String[] args) { String str1 = "Character"; String str2 = "character"; StringBuffer sb = new StringBuffer("Character"); boolean result = str1.contentEquals(sb); System.out.println(result); result = str2.contentEquals(sb); System.out.println(result); } }
Output
true false
Description
public boolean contentEquals​(StringBuffer sb)
Compares this string to the specified StringBuffer. The result is true if and only if this String represents the same sequence of characters as the specified StringBuffer. This method synchronizes on the StringBuffer.
For finer-grained String comparison, refer to Collator.
Parameters:
sb – The StringBuffer to compare this String against
Returns:
true if this String represents the same sequence of characters as the specified StringBuffer, false otherwise
Since:
1.4