WHY STRING OBJECTS ARE IMMUTABLE IN JAVA?

Mayank Tripathi

Total Post:807

Points:4035
Posted by  Mayank Tripathi
Java  String 
 541  View(s)
Ratings:
Rate this:
  1. Mayank Tripathi

    Post:807

    Points:4035
    Why string objects are immutable in java?

    Because java uses the concept of string literal. Suppose there are 5 reference variables,all referes to one object "sachin".If one reference variable changes the value of the object, it will be affected to all the reference variables. That is why string objects are immutable in java.

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!