In Java 8, I wrote some sample code.
String s1 = "Hello";
String s2 = "world";
String s3 = s1 + s2;
After decompiling .class file I found that 3rd statement
String s3 = s1 + s2;
replaced by
String s3 = new StringBuilder(s1).append(s2).toString();
Does it mean that There is no longer need to use explicit StringBuilder for Optimization and just use '+' operator instead of?
Yes. Actually, this optimization had been done in Java 6. See Bruce Eckel's "Thinking in Java" 4th edition pp.356-359 for details
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With