String

Why String is Immutable or Final in Java

For example, if one client changes the value of String "Test" to "TEST", all other clients will also see that value as explained in the first example. Since caching of String objects was important from performance reason this risk was avoided by making class Immutable. At the same time, String was made final so that no one can compromise invariant of class e.g. Immutability, Caching, hashcode calculation etc by extending and overriding behaviors. Another reason of why class is immutable could die due to HashMap.

10 Things Every Java Programmer Should Know About String At Infocampus

Given heavy use of Java String in almost any kind of project, it become even more important to know subtle detail about String. Though I have shared lot of String related article already here in Javarevisited, this is an effort to bring some of String feature together. In this tutorial we will see some important points about Java , which is worth remembering. You can also refer my earlier post 10 advanced Java questions to know more about String.

«PreviousPage: 1Next»