Card 09/ 09
All 9 cards
RecapDifficulty: Intermediate1 min
What Never Changes, and What That Costs
Five things this topic established, and where each one was.
| The thing | Where |
|---|---|
No String method changes the string; every one returns a new one | Why Changing a String Gives You a Different String |
| A result you do not assign is a result you threw away | Trimming a Line From a File and Losing the Result |
Literals are pooled and shared; new String opts out | Two Ways to Make the Same Text |
== compares addresses, so text comparison is always .equals | Why == Says Two Identical Strings Are Different |
+= in a loop copies everything so far on every pass; a builder does not | What += 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.