Java Strings

1 question, most-asked first.

  • Why is String immutable, and what is the string pool?

    String is immutable because nothing in its API exposes a mutator — not because its byte[] field is final. The pool is a JVM-wide cache of literals that makes == accidentally work on literals and fail everywhere else.

    Asked constantlyintermediate0–8 yrs9 min read