When you need to build a string piece by piece, use StringBuilder. It is a mutable object, meaning you can modify its contents without creating new objects each time.
StringBuilder sb = new StringBuilder();
sb.append("Hello");
sb.append(" ");
sb.append("World");
String result = sb.toString();
System.out.println(result);
This prints Hello World. Each .append() call modifies the same StringBuilder object in place. When you are finished, .toString() converts it to a regular String.
StringBuilder also supports .insert() to add text at a specific position, .delete() to remove a range, and .reverse() to flip the entire contents. Unlike String, these operations modify the object directly instead of returning a new copy.