Recall from Basic Java When We Discussed Snapshot Diagrams That Some Objects Are Immutable: Once Created, They Always Represent the Same Value. Other Objects...
Recall from Basic Java when we discussed snapshot diagrams that some objects are immutable: once created, they always represent the same value. Other objects are mutable: they have methods that change the value of the object. String is an example of an immutable type. A String object always represents the same string.
Why string is mutable or immutable?
If one reference variable changes the value of the object, it will be affected by all the reference variables. That is why String objects are immutable in Java. Following are some features of String which makes String objects immutable.
The String is immutable in Java because of the security, synchronization and concurrency, caching, and class loading. The reason of making string final is to destroy the immutability and to not allow others to extend it. The String objects are cached in the String pool, and it makes the String immutable.
Alexander Ross has covered the video game industry for a decade, writing deep dives on game design, esports tournaments, VR developments, and gaming culture.