Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Java Java Basics Perfecting the Prototype Censoring Words - Using String Equality

Mark Gormley
Mark Gormley
543 Points

Is the method equals the same as contentEquals?

Just reading the doc, it has equals which is what we use and contentEquals. Are they the same thing?

1 Answer

Mihai Craciun
Mihai Craciun
13,520 Points

Not really,

The method contentEquals accepts as a parameter a StringBuffer which is quite similar to a String but can be modified. At any point in time it contains some particular sequence of characters, but the length and content of the sequence can be changed through certain method calls.

The method equals on the other hand accepts an object and it compares 2 objects. It can be a simple built-in object like a String or it can be a an Object made by you.