wh开发者_C百科at is the difference between the StringBuffer vs StringBuilder Vs StringTokenizer on the internal implementation. when to use these . kindly waiting for the answer.
Update:-
I am also going through the source code.
StringBuffer
- introduced in JDK 1.0 - is thread safe (all of its methods are synchronized
), while StringBuilder
- since JDK 1.5 - is not. Thus it is recommended to use the latter under normal circumstances.
StringTokenizer
is meant for a whole different purpose then the former two: cutting strings into pieces, rather than assembling. As @Henning noted, it is also "retired" since JDK 1.5 - it is recommended to use String.split
instead.
StringBuffer is designed to be thread-safe and all public methods in StringBuffer are synchronized. StringBuilder does not handle thread-safety issue and none of its methods is synchronized.
StringBuilder has better performance than StringBuffer under most circumstances.
Use the new StringBuilder wherever possible.
Here is performance comparison
of StringBuilder & StringBuffer
StringBuilder & StringBuffer Holds String where StringoTokeizer class allows an application to break a string into tokens .. So It is like odd one out
StringBuffer - is synchronized version of StringBuilder (introduced after its unsynchronized peer)
StringBuffer serves same purpose as StringBuilder except that StringBuffer is thread-safe.
StringTokenizer is used for splitting the string into tokens based on some delimiters.
精彩评论