As others have said already,
String and StringBuffer are quite different, so there are not all that many situations where you could actually swap one for the other.
Note, though, that StringBuffer is mostly superceded by StringBuilder, in
Java 5 onwards.
You should not use StringBuffer in new code, but instead should use StringBuilder.
The reason for preferring StringBuilder is that it is not encumbered with pointless synchronisation. Very few uses of StringBuffer actually made use of its synchronisation, but all suffered the performance costs of it.
As a beginner, you don't really need to understand the paragraph above. Just remember that, if you are writing for Java 5 or newer, use StringBuilder.