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 trialFurquan Ahmad
5,148 PointsHi i don't really understand what the =+ does in Java Strings
I thought =+ was used for adding the current value + the new one.
int x = 10;
int y = 3;
int x += y;
How does it work in Strings
public boolean applyGuess (char letter) {
boolean isHit = mAnswer.indexOf(letter) >= 0;
if (isHit) {
mAnswer += letter;
}
}
1 Answer
Mark VonGyer
21,239 PointsIt is basically short for:
x = x + y;
x += y;
If you're like me you will get this the wrong way round many times ( x =+y).
Furquan Ahmad
5,148 PointsI understand it like this but as a string for what i see it's just used for concatenation purposes.
String example = Manchester;
String example1 = United;
String += example1;
Will result in Manchester United.
Handan Γnal
521 PointsHandan Γnal
521 PointsIt adds the string at the and of the first string, to be more clear It concetenates. In the code you have copied, if the letter exists, It adds the letter to mAnswer string (after the first "letter" character is shown)