Home >>Java String Methods >Java String contentEquals() Method

Java String contentEquals() Method

Java String contentEquals() Method

The contentEquals() method in Java String is used to searches a string to find out if it contains the exact same sequence of characters in the specified string or StringBuffer and Returns true if the characters exist and false if not.

Syntax

There are 2 contentEquals() methods:

public boolean contentEquals(StringBuffer chars)
public boolean contentEquals(CharSequence chars)

Parameter

StringBuffer chars - This parameter is used to searches the StringBuffer

CharSequence chars - This parameter is used to searched the sequence of characters

Technical Details

Returns - It is used to returns a boolean, indicating whether the exact same sequence of characters exist in the specified string (or StringBuffer):

  • true – It returns the sequence of characters exists
  • false – It returns the sequence of characters do not exist

Java String contentEquals() Method:


public class Main 
{
public static void main(String[] args) 
{
String strln1 = "phptpoint";
System.out.println(strln1.contentEquals("phptpoint"));
System.out.println(strln1.contentEquals("p"));
System.out.println(strln1.contentEquals("Hey"));
}
}

Output:
true
false
false

No Sidebar ads