Managing strings
The class String is used a lot. So, you have to have a good handle on its functionality. We talked already talked about String value immutability in Chapter 5, Java Language Elements and Types. We have shown that every time a String value is "modified", a new copy of the value is created, which means that in the case of multiple "modifications", many String objects are created, consuming memory and putting a burden on the JVM.
In such cases, it is advisable to use the class java.lang.StringBuilder or java.lang.StringBuffer because they are modifiable objects and do not have an overhead of creating String value copies. We will show how to use them and explain the difference between these two classes in the first part of this ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access