138k views
0 votes
Why is String final in Java?

User Ky
by
4.1k points

1 Answer

1 vote

Answer:

string objects are cached in string pool.

Step-by-step explanation:

Strings in Java are immutable or final because the string objects are cached in String Pool.As we know multiple clients share the string literals so there exists a risk of one client's action affecting all other clients.

For ex:-The value of string is "Roast" and client changed it to "ROAST" so all other clients will see ROAST instead of Roast.

User Carl Sednaoui
by
4.6k points