Explain the difference between StringBuilder and StringBuffer class.StringBuffer class is contained in java.lang package. This class is mutable means the character string in a string buffer gets changed, but the buffer’s capacity can also change dynamically. StringBuffer is thread safe that means it is synchronized.
JDK1.5 provides another class called StringBuilder, it is same as StingBuffer but it is not thread safe. This is used where the StringBuffer was being used by a single thread. Where possible, it is recommended that this class be used in preference to StringBuffer as it will be faster under most implementations.
|