Java String contentEquals() Method

You are Here:

Java String contentEquals()

The contentEquals() method compares the String with the String Buffer and returns a boolean value.

In the following example, we will compare the string with the String Buffer.

Example

Java Compiler
public class myClass { public static void main(String[] args) { String str1 = "John Doe"; StringBuffer str2 = new StringBuffer("John Doe"); StringBuffer str3 = new StringBuffer("JOHN DOE"); System.out.println(str1.contentEquals(str2)); System.out.println(str1.contentEquals(str3)); } }

Output

true false

Syntax

public boolean contentEquals(str2)

Parameter Values

ValueTypeExplanation
str2RequiredSpecifies the StringBuffer or the sequence of characters to be searched for.

Return Value

ValueExplanation
trueIf the sequence of characters exist.
falseIf the sequence of characters do no exist.

More Examples

In the following example, we will compare the string with the sequence of characters.

Example

Java Compiler
public class myClass { public static void main(String[] args) { String str1 = "John Doe"; String str2 = "John Doe"; String str3 = "JOHN DOE"; System.out.println(str1.contentEquals(str2)); System.out.println(str1.contentEquals(str3)); } }

Output

true false

Reminder

Hi Developers, we almost covered 90% of String functions and Interview Question on Java with examples for quick and easy learning.

We are working to cover every Single Concept in Java.

Please do google search for:

Join Our Channel

Join our telegram channel to get an instant update on depreciation and new features on HTML, CSS, JavaScript, jQuery, Node.js, PHP and Python.

This channel is primarily useful for Full Stack Web Developer.

Share this Page

Meet the Author