<p>Someone told me it's more efficient to use <code>StringBuffer</code> to concatenate strings in Java than to use the <code>+</code> operator for <code>String</code>s. What happens under the hood when you do that? What does <code>StringBuffer</code> do differently?</p>

One shouldn't be faster than the other. This wasn't true before Java 1.4.2, because when concatenating more than two strings using the "+" operator, intermediate
```
String
```
objects would be created during the process of building the final string.
However, as the
JavaDoc for StringBuffer
states, at least since Java 1.4.2 using the "+" operator compiles down to creating a
```
StringBuffer
```
and
```
append()
```
ing the many strings to it. So no difference, apparently.
However, be careful when using adding a string to another inside a loop! For example:
```
```
String myString = "";

for (String s : listOfStrings) {
  // Be careful! You're creating one intermediate String object
  // for every iteration on the list (this is costly!)
  myString += s;
}
```
```
Keep in mind, however, that usually concatenating a few strings with "+" is cleaner than
```
append()
```
ing them all.