java - When to use string concat -


i have read quite few articles on +, stringbuilderappend , concat. but, if have 1 single concatenation best option?

  1. str1 + str2
  2. use string builder
  3. use string concat

i looking explanation when , 2 strings involved.

also when 2 strings involved complexity of string concat o(n) n length of longest string?

if you're doing single concatenation, use str1 + str2. easy read, , translated string concat compiler, fine if you're not going through loop or something. in fact, it's faster using stringbuilder if you're going concatenate strings single time.

see http://blog.codinghorror.com/the-sad-tragedy-of-micro-optimization-theater/ description of why shouldn't bother using string builder if you're not looping.

also when 2 strings involved complexity of string concat o(n) n length of longest string?

you that. i'd it's o(n) n combined length of 2 strings, since shortest string cannot, definition, order of magnitude larger longest string comes out same.


Comments

Popular posts from this blog

python - mat is not a numerical tuple : openCV error -

c# - MSAA finds controls UI Automation doesn't -

wordpress - .htaccess: RewriteRule: bad flag delimiters -