top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

Why String is unchangeable in Java?

+1 vote
362 views
Why String is unchangeable in Java?
posted Jun 12, 2014 by Balwinder

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

1 Answer

+1 vote

Reasons:

  1. String pool requires string to be immutable otherwise shared reference can be changed from anywhere.

  2. Security because 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 Jun 13, 2014 by Rahul Vaidya
...