Complexity of setLength differs from operation ( increase or decrease ) complexity of increase operation is not O(1), I think it is O(n), because, in this operation new array will be generated, and each unused byte of stringbuilder with replaced by '\0' byte
But decrease operation is O(1) complexity , because of that in this operation only count of characters will be changed.
There is source of setLength method in StringBuilder class source file
http://developer.classpath.org/doc/java/lang/StringBuilder-source.html
225: public void setLength(int newLength) 226: { 227: if (newLength < 0) 228: throw new StringIndexOutOfBoundsException(newLength); 229: 230: int valueLength = value.length; 231: 232: /* Always call ensureCapacity in order to preserve copy-on-write 233: semantics. */ 234: ensureCapacity(newLength); 235: 236: if (newLength < valueLength) 237: { 238: /* If the StringBuilder's value just grew, then we know that 239: value is newly allocated and the region between count and 240: newLength is filled with '\0'. */ 241: count = newLength; 242: } 243: else 244: { 245: /* The StringBuilder's value doesn't need to grow. However, 246: we should clear out any cruft that may exist. */ 247: while (count < newLength) 248: value[count++] = '\0'; 249: } 250: }