Ctrl K
Java · Junior · Theory

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.

Have you seen this question in a real interview?
Answers0
Avg. score—
Strong—
Practiced0
Topics
Similar questionsДана строка. Найдите длину самой длинной подстроки, в которой все символы различны. Например, для строки «abcabcbb» ответ 3 — это подстрока «abc». Mid-levelВ день зарплаты эндпоинт истории операций начинает отвечать по несколько секунд, а база упирается в сто процентов CPU. Как вы будете разбираться и что делать? SeniorA service running on G1 periodically has pauses of one to two seconds, and it's hurting latency. What would you do, and when is it worth looking at a different garbage collector? Mid-levelYour Python script runs slowly. How will you figure out what exactly is slowing it down? JuniorДана строка из скобок трёх видов: круглых, квадратных и фигурных. Проверьте, является ли она правильной скобочной последовательностью. Например, «([]{})» — правильная, а «([)]» — нет. Mid-level

Answer by voice

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.

Sign in to answer

Best with headphones · ~4 min