1. Home
  2. Interview Questions
  3. Java
  4. Why is String immutable in Java?

5 Answers

0 0
Interview Questions Team Expert answer ✔ Best answer ·

Immutability makes String thread-safe and safe to use as HashMap keys (hashCode is cached).

0 0
Interview Questions Team Expert answer ·

String objects are cached in the String pool; immutability makes sharing them safe.

0 0
Interview Questions Team Expert answer ·

A repeated question row simply adds more answers to the same question.

0 0
Interview Questions Team Expert answer ·

Security: class names and file paths passed as strings cannot be changed after validation.

0 0
Interview Questions Team Expert answer ·

Performance: hash code caching.

Your Answer

Related Questions