What are the differences between String, StringBuffer, and StringBuilder in java?

All Java developers use the string in every day’s coding. It is impossible to pass days as a developer without using the Java String class. We also have StringBuffer and StringBuilder classes in Java. Following are some differences of String, StringBuffer and StringBuilder:

#StringStringBufferStringBuilder
1String is immutableStringBuffer is mutableStringBuilder is mutable
2String is thread-safeStringBuffer is thread-safeStringBuilder is not thread-safe
3String is fastStringBuffer is very slowStringBuilder is fast
4String storage area is constant string poolStringBuffer storage area is heapStringBuilder storage area is heap

We should prefer StringBuilder in all cases where we have only a single thread accessing the object.