🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← Strings Quiz: all 8 questions

Strings Quiz · Question 1 of 8

Why is s = s + ch inside a loop slow in Java and Python?

Why is s = s + ch inside a loop slow in Java and Python?

  1. A.Strings can only hold 255 characters
  2. B.Strings are immutable, so each + copies the whole string
  3. C.The + operator is not defined for strings
  4. D.It isn't slow
Answer & explanation

Correct answer: Strings are immutable, so each + copies the whole string

Every concatenation creates a new string and copies the old characters → O(n²) overall. Use StringBuilder / "".join().

Can you get the rest right without peeking?

Take the timed Strings Quiz quiz free. Pass it to earn XP and count towards your certificate.

Start the quiz →