Reasons Why String is Immutable?

Strings in Java are immutable (cannot be changed after creation). Here’s why this design choice matters:
1)Security & Safety

       Used for sensitive data like passwords, URLs, and database connections.

       If String were mutable, hackers could alter its value after creation, leading to security risks.

  2)Thread Safety

     Immutable objects are automatically thread-safe.

     Multiple threads can read a String without risk of modification.

     3)Performance


Since strings are reused from the pool and not modified, it reduces memory overhead and increases performance


Real-Life Example

Imagine a bank account number stored as a String. If mutable, someone could modify it after creation—leading to fraud!