String, StringBuffer, and StringBuilder

Mutability Difference: String is immutable, if you try to alter their values, another object gets created, whereas StringBuffer and StringBuilder are mutable so they can change their values. Thread-Safety Difference: The difference between StringBuffer and StringBuilder is that StringBuffer is thread-safe. So when the application needs to be run only in a single thread then … Read more

StringBuilder vs String concatenation in toString() in Java

Version 1 is preferable because it is shorter and the compiler will in fact turn it into version 2 – no performance difference whatsoever. More importantly given we have only 3 properties it might not make a difference, but at what point do you switch from concat to builder? At the point where you’re concatenating … Read more