A String is a string. A StringBuffer is a tool for building Strings.
When you need to pass an argument to a method named, say, setName(), the argument, presumably a "name", ought to be a String. When you need to return something from a method named, say, getName(), and it's supposed to return the "name" of something, then that method should return a String.
But let's say you have an array containing the names of the 50 states, and you need to loop over that array and build a comma-separated sentence like
"The 50 states are Alabama, Alaska, Arkansas..."
then you'll want to use a StringBuffer to accumulate the result, rather than using Strings and the "+" operator; it will be much more efficient.
Ernest's example illustrates a certain situation where you should prefer StringBuffer over String. To generalize this a little, StringBuffer should be preferred when you are building a string. Whereas String is useful when the string is "static" (i.e. its contents don't change except to replace it by a completely new and unreleated string).
# Within a single string assignment, using String concatenation is fine. # If you're looping to build up a large block of character data, go for StringBuffer. # Using += on a String is always going to be less efficient than using a StringBuffer, so it should ring warning bells - but in certain cases the optimisation gained will be negligible compared with the readability issues, so use your common sense.
There will be glitches in my transition from being a saloon bar sage to a world statesman. - Tony Banks