Home » Core Java » java.lang.StringBuilder

java.lang.StringBuilder

 

java.lang.StringBuilder

1 : A mutable sequence of characters. This class provides an API compatible with StringBuffer, but with no guarantee of synchronization.
2 : This class is preferred over StringBuffer in a single thread model as it is faster than StringBuffer.
3 : Every string builder has a capacity. As long as the length of the character sequence contained in the string builder does not exceed the capacity,
it is not necessary to allocate a new internal buffer. If the internal buffer overflows, it is automatically made larger.
4 : Instances of StringBuilder are not safe for use by multiple threads.If such synchronization is required then it is recommended that java.lang.StringBuffer be used.

The principal operations on a StringBuilder are the append and insert methods, which are overloaded so as to accept data of any type.Each effectively converts a given datum to a string and then appends or inserts the characters of that string to the string builder.The append method always adds these characters at the end of the builder; the insert method adds the characters at a specified point.

For example, if z refers to a string builder object whose current contents are “start”, then the method call z.append(“le”) would causethe string builder to contain “startle”, whereas z.insert(4, “le”) would alter the string builder to contain “starlet”.The principal operations on a StringBuilder are the append and insert methods, which are overloaded so as to accept data of any type.Each effectively converts a given datum to a string and then appends or inserts the characters of that string to the string builder.The append method always adds these characters at the end of the builder; the insert method adds the characters at a specified point.
 
 


Leave a comment

Your email address will not be published. Required fields are marked *

19 − 11 =