Concatenation with + operator will be internally converted to a StringBuffer( as synchronized version of StringBuilder class). IMO there isn't much performance difference unless you are trying to concatenate in a loop, in such cases StringBuilder would be a better option.
Also, since StringBuffer is synchronized, depending on how you are using the String object in the VM StringBuilder may outperform "+" approach. (Take a look a the StackOverflow discussion) Also, I feel StringBuilder improves readability of a code. Plus, http://docs.oracle.com/javase/specs/jls/se5.0/html/expressions.html#15.18.1.2 http://stackoverflow.com/questions/355089/stringbuilder-and-stringbuffer Chaitanya M Bhatt http://www.performancecompetence.com On Sun, Dec 28, 2014 at 4:34 AM, Felix Schumacher < [email protected]> wrote: > Hi all, > > in XPathUtil I have found the following code fragment: > > log.debug(new StringBuilder("bla").append(blub).append("whatever"). > toString()) > > which seems to me t be equivallent to > > log.debug("bla"+blubb+"whatever") > > any reason to use the former? > > Regards > Felix >
