top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

Why String is Immutable or Final in Java?

0 votes
437 views
Why String is Immutable or Final in Java?
posted May 13, 2016 by anonymous

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

2 Answers

+1 vote

The string is Immutable in Java because String objects are cached in String pool. Since cached String literals are shared between multiple clients there is always a risk, where one client's action would affect all another client.

answer May 14, 2016 by Kapil Kumar
0 votes

String is shared on different area like file system, networking connection, database connection , having immutable string allows you to be secure and safe because no one can change reference of string once it gets created. if string had been mutable anyone can surpass the security be logging in someone else name and then later modifying file belongs to other.

answer Feb 4, 2017 by Manisha
...