String — immutable. StringBuilder — mutable, not thread-safe. StringBuffer — mutable, thread-safe.
String:
1String s = "Hello";2s += " World"; // Creates NEW string3s += "!"; // Creates another NEW string4// 3 string objects created!
StringBuilder:
1StringBuilder sb = new StringBuilder();2sb.append("Hello");3sb.append(" World");4sb.append("!");5String result = sb.toString();6// Only 1 final string created
StringBuffer:
1StringBuffer sb = new StringBuffer();2sb.append("Hello");
When to use: