Why are strings immutable in Java, and why shouldn't you concatenate strings with plus in a loop?
~4 min by voice
How to approach it
The interviewer checks whether the candidate understands the memory model of String in Java: immutability and the reasons for it, the string pool, the cost of concatenation in a loop and the right tool (StringBuilder). Along the way they look at basic hygiene: comparing with equals.
The interviewer will ask this question and listen. Think out loud and ask for a hint if you need one. When you're done, pause or tap “That's my answer”. In about a minute, your score and the points you covered show up here.