Skip to content
Sharp

Engineering Interviews · interview question

Why is it important for Java Strings to be immutable?

Multiple choiceMediumchapter-20-curatedpremiumengineering-interviewsjvm-trivia
Choose one answer
Answer and explanation

Correct answer

D. To enhance performance and security, especially in multithreaded contexts.

Why

String immutability in Java enhances performance by allowing string literals to be reused via the string pool, and it provides security by preventing string value changes after creation. This is particularly beneficial in multithreaded applications, where shared data integrity is crucial.

Test yourself on Engineering Interviews

A free test with instant, explained results. No account needed.

Start free test
All Engineering Interviews questions →