This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
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?
How do we know it's actually concatenating them? At least for s1 and s2, perhaps println() just references their memory locations, prints the data in those references, and doesn't actually do any string manipulation hence the reason no new objects are created. Dunno about the " " though.
Just a shot in the dark.
Scooby Snacks for everyone...<br /> <br />SCJA, SCJP 1.4