public final class StringBuilder extends Object implements Serializable, CharSequence

  1. mutable
  2. provides APIs compatible with StringBuffer, but no guarantee of synchronization.
  3. Faster than StringBuffer;
  4. Not thread-safe

e.g. z refers to a string builder object whose current content are start, then z.append("le") would cause string builder to contain startle, z.insert(4, "le") would alter the string builder to contain starlet.

StringBuilder is not good for multiple threads. If such synchronization is required, use StringBuffer.

APIs:

  • append(),
  • charAt(),
  • capacity(),
  • delete(int start, int end),
  • deleteCharAt(int index),
  • indexOf(),
  • insert(int offset, xxx X),
  • replace(int start, int end, String str),
  • reverse(),
  • setChatAt(int index, char ch),
  • CharSequence subSequence(int start, int end),
  • String substring(int start, int end)