JavaBeginner#strings

What is the difference between String, StringBuilder, and StringBuffer?

String is immutable. StringBuilder is mutable and not thread-safe (fast). StringBuffer is mutable and synchronized (thread-safe, slower). Use StringBuilder for single-threaded concatenation in loops.

Example
StringBuilder sb = new StringBuilder();
for (int i = 0; i < 5; i++) sb.append(i);
System.out.println(sb.toString()); // "01234"

Related Questions

1
JavaIntermediate#strings

Why are Strings immutable in Java?

Open
2
JavaIntermediate#collections

Explain the Collections framework hierarchy.

Open
3
JavaBeginner#collections#list

ArrayList vs LinkedList?

Open