java - When to use string concat -
i have read quite few articles on +, stringbuilderappend , concat. but, if have 1 single concatenation best option?
- str1 + str2
- use string builder
- 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
Post a Comment