Hi,
I'm using the SCJP5 Study Guide by Sierra and Bates (great book by the way) to study for the exam, and I have a question regarding an example in the book on
String objects and immutability:
1. String s1 = "spring ";
2. String s2 = s1 + "summer ";
3. s1.concat("fall ");
4. s2.concat(s1);
5. s1 += "winter ";
6. System.out.println(s1 + " " + s2);
Now, the book states that 8 String objects are created in total: "spring ", "summer ", "spring summer ", "fall", "spring fall ", "spring summer spring", "winter", "spring winter". My question is then: would not line 6 also create some String objects, at least the object with value " ", but also (s1 + " ") and (s1 + " " + s2) during the + operations?
jarle