Home >>Java String Methods >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.
There are 2 contentEquals() methods:
public boolean contentEquals(StringBuffer chars)
public boolean contentEquals(CharSequence chars)
StringBuffer chars - This parameter is used to searches the StringBuffer
CharSequence chars - This parameter is used to searched the sequence of characters
Returns - It is used to returns a boolean, indicating whether the exact same sequence of characters exist in the specified string (or StringBuffer):
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"));
}
}