Why is String immutable?

String is immutable in Java, which means that once a String object is created, its value cannot be changed. Any operation that appears to modify a String actually creates a new String object. This design improves security, performance, thread safety, and memory efficiency.

Key Points

Example

When a String is modified using concatenation, Java creates a new object instead of changing the existing one.

public class Demo {

    public static void main(String[] args) {

        String str = "Java";

        str.concat(" Programming");

        System.out.println(str);

        str = str.concat(" Programming");

        System.out.println(str);
    }
}

Output

Java

Java Programming

Benefits of String Immutability

Common Mistakes

Follow-up Questions

Interview Tip

A concise interview answer is

String is immutable in Java, meaning its value cannot be changed after creation. This design improves security, enables String Pool optimization, provides thread safety, and enhances performance through hash code caching and efficient memory management.

Last updated: 11 November 2026

Previous question: What is the difference between a String literal and a String object?

Next question: Why are packages used in Java?

More Core Java - Level II interview questions

All Core Java - Level II questions