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

javascript - How do I find how many occurences are there of a highlighted string, and which occurence is it? -

javascript - How to synchronize the Three.js and HTML/SVG coordinate systems (especially w.r.t. the y-axis)? -

java - Reading data from multiple zip files and combining them to one -