Java StringBuffer versus String: When to use StringBuffer

The most common reason to use a StringBuffer instead of a String in your Java programs is when you need to make a lot of changes to a string of characters. For instance, a lot of times you’ll be creating a string of characters that is growing, as shown in this sample example program: