Both StringBuilder and StringBuffer are mutable string builders. StringBuffer is synchronized (thread-safe but slow). StringBuilder is non-synchronized (fast but not thread-safe). Use StringBuilder in single-threaded contexts for performance. Use StringBuffer only in legacy multithreaded code.
StringBuffer: A shared notebook with locks (only one person writes at a time). StringBuilder: A personal notebook (only you write).
When would you use StringBuffer over StringBuilder in modern Java?