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
Jake Henry
4,787 PointsAbout escaping quotes?
Why does the \"" in the following code work when logically wouldn't it be like this "\" as it is after mDescription. It seems like this would print out "" mDescription" .
This is the code : public String toString() {
return "Treet: \"" + mDescription + "\" - @" + mAuthor;
1 Answer
Steven Parker
243,266 PointsOne is an ending, one is a beginning.
That first cluster of symbols (\"") is an escaped quote that is at the end of a literal string, which is being closed by the other (unescaped) quote. The whole literal string is: "Treet: \"", which represents this as the actual content:
Treet: "
The second bundle of symbols is where an escaped quote is at the beginning of a literal string. The whole string is: "\" - @", which represents this content:
" - @
All of this is so mDescription which is being concatenated with these literals will appear in the output with quotes on either side.
Jake Henry
4,787 PointsJake Henry
4,787 PointsOk, I was looking at the escape quote backwards and upside down. Now it makes perfect sense, Thank you!