Java String contentEquals() method example

HQ » Java Tutorial » java.lang » String » contentEquals() method example
Java String contentEquals() method example 2018-02-19T12:43:09+00:00

java.lang.String contentEquals()

Description :

This java tutorial shows how to use the contentEquals() method of java.lang.String class. This method returns a boolean data type if the input parameter is equal to the String in terms of character sequence.

Method Syntax :

public boolean contentEquals(StringBuffer sb)
public boolean contentEquals(CharSequence cs)

Parameter Input :

Data Type Parameter Description
StringBuffer sb The String is compared to this StringBuffer character sequence
CharSequence cs The String is compared to this Charsequence

Method Returns :

This method returns booelan datatype that corresponds to the character sequence equality of the String to the parameter input.

Compatibility Version :

Requires Java 1.4 for Stringbuffer parameter input
Requires Java 1.5 for CharSequence parameter input

Java Code Example :

This example source code demonstrates the use of contentEquals(StringBuffer sb) method of String class. A String variable equals to “Mark Philly” will be compared to the input coming from the console input. The input is break down first in first name and last name. The two input strings will be combined into one string ‘full name’ using StringBuffer append method.

Sample Output :

Running the contentEquals() example source code will give you the following output

java string contentequals method example

java string contentequals method example

Suggested Reading List :


Contact Info


Our Goal

JavaTutorialHQ aims to to be The Ultimate Guide on Java with hundreds of examples from basic to advance Topics.

By continuing to use the site, you agree to the use of cookies. more information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.