Card 09/ 09
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.
| The idea | Where |
|---|---|
No String method changes the string; every one returns a new one | String Immutability: Why String Methods Return a New String |
| A result you do not assign is a result you threw away | String Immutability Example: A Stripped Line That Was Never Kept |
Literals are pooled and shared; new String opts out | The String Pool: Why Identical Literals Are Shared |
== compares addresses, so text comparison is always equals | Comparing Strings: equals, Not == |
+= in a loop copies everything so far on every pass; a builder does not | String 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.
← → move through sections and cards