I am aware of String concatenation: concat() vs + operator
But i have question on usage of both concat() and + operator effectively
concat() is more efficient than
+ operator but still we are using
+ operator in few cases below
System.out.println("Hi! Welcome: "+nameString);
splitting huge length line in to multiple lines(eclipse formatting)
System.out.println("Hi! Welcome: "+nameString1
why still we are using
+ operator instead of
Best How To :
There's are difference.
aStr is null, then
aStr += bStr will treat the original value of
aStr as if it were
concat() method accepts just
String instead the
+ operator which converts the argument to
concat() method is more strict in what it accepts.
Also, if you have lot of String concatenations with
+, I highly recommend to work with mutable
StringBuilder object that will increase speed of your code.