Card 09/ 09

RecapDifficulty: Intermediate1 min

Recap: Strings

Immutability, lost results, the pool, equals and builders, with where each was.

Strings come down to the five ideas below, each listed with the card that covers it.

What the topic established, and which card it was on
The ideaWhere
No String method changes the string; every one returns a new oneString Immutability: Why String Methods Return a New String
A result you do not assign is a result you threw awayString Immutability Example: A Stripped Line That Was Never Kept
Literals are pooled and shared; new String opts outThe String Pool: Why Identical Literals Are Shared
== compares addresses, so text comparison is always equalsComparing Strings: equals, Not ==
+= in a loop copies everything so far on every pass; a builder does notString Concatenation in a Loop: What += Costs

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.