Please tell me a real time situation to compare String, StringBuffer, and StringBuilder?
String may carry an unacceptable performance penalty, either in CPU time or memory (obtaining substrings is CPU efficient because the data is not copied, but this means a potentially much larger amount of data may remain allocated).StringBuilder, but when changes to the underlying string must be synchronized (because several threads are reading/modifyind the string buffer).See an example here.