When you decere like this . Are the instances created?
String string = "a"+"b"+"c";
Should it be declared like following?
StringBuilder sBuilder = new StringBuilder();
sBuilder.append("a");
sBuilder.append("b");
sBuilder.append("c");
For
String string = "a"+"b"+"c";
The compiler generates a complete string. The bytecode looks like this. Most compilers would do it this way since it is working with constants. Variable concatenation may be handled differently depending on the version of the JDK.
0 ldc <String "abc"> [16]
2 astore_1 [string]
So the following would be unnecessary overhead.
StringBuilder sBuilder = new StringBuilder();
sBuilder.append("a");
sBuilder.append("b");
sBuilder.append("c");
However, if you ever need to call append on the same StringBuilder
object you can do the following:
StringBuilder sBuilder = new StringBuilder();
sBuilder.append("a").append("b").append("c");
StringBuilder.append
returns its own instance.