Latest web development tutorials

Java contentEquals () method

Java String class Java String class


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

grammar

public boolean contentEquals(StringBuffer sb)

parameter

  • sb - to compare the string StringBuffer.

return value

Such as a string with the specified StringBuffer represent the same sequence of characters, it returns true; otherwise 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 above program execution results:

true
false

Java String class Java String class