In ArrayList
the add operation is amortized operation. So while reading StringBuffer
it came to my mind why the StringBuffer
is not amortized. Suppose I use append operation on a string buffer object then it should be able to add those many no of characters in it's underlying array implementation. But instead I found in source code that we have
System.arraycopy(chars, 0, value, count, chars.length);
in append operation of string buffer. So my question is can't the StringBuffer
be amortized so it can give us less that O(N) complexity?