I\'m pasting this text from an ebook I have. It says the complexity if O(n2) and also gives an explanation for it, but I fail to see how.
Question: What i
The accepted answer is just wrong. StringBuffer has amortized O(1) append, so n appends will be O(n).
StringBuffer
If it wasn't O(1) append, StringBuffer would have no reason to exist, since writing that loop with plain String concatenation would be O(n^2) as well!
String