jmeter-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chaitanya bhatt <bhatt.chaita...@gmail.com>
Subject Re: StringBuilder against compile time String concatenation
Date Wed, 31 Dec 2014 18:15:03 GMT
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 <
felix.schumacher@internetallee.de> 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
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message