Card 09/ 09

RecapDifficulty: Intermediate1 min

What Never Changes, and What That Costs

Five things this topic established, and where each one was.

What the topic established, and which card it was on
The thingWhere
No String method changes the string; every one returns a new oneWhy Changing a String Gives You a Different String
A result you do not assign is a result you threw awayTrimming a Line From a File and Losing the Result
Literals are pooled and shared; new String opts outTwo Ways to Make the Same Text
== compares addresses, so text comparison is always .equalsWhy == Says Two Identical Strings Are Different
+= in a loop copies everything so far on every pass; a builder does notWhat += Really Does, Once per Pass

Immutability is the single fact underneath all five. It is why methods return new strings, why literals can be shared safely, why identity and equality come apart, and why building text one piece at a time needs a different type.