String methods – contentEquals

ContentEquals() is used to compare the string. It has 2 types of implementations.

  1. boolean contentEquals(CharSequence cs)
  2. boolean contentEquals(StringBuffer sb)

Let’s understand them with the help of examples.

boolean contentEquals(CharSequence cs):

Returns true if string matches with the specified sequence of characters, else returns false.

Output:
true
false

 

boolean contentEquals(StringBuffer sb):

This method compares the String with String buffer. If both matches returns true, else return false.

Output:
true
false
Ask Question
Have any question or suggestion for us?Please feel free to post in Q&A Forum
String methods - startsWith and endsWith
String methods - getBytes() and getChars()
Shekhar Sharma

Shekhar Sharma

Shekhar Sharma is founder of testingpool.com. This website is his window to the world. He believes that ,"Knowledge increases by sharing but not by saving".

You may also like...