StringBuilder in java
StringBuilder is same as StringBuffer except that StringBuilder is not synchronized, hence it is not thread-safe.
i.e. StringBuilder class objects are non-thread-safe , mutable sequence of characters.
Note: StringBuilder not override equals method of object class, so StringBuilder objects should be converted into string objects if you want to compare StringBuilder class objects.
Constructors of StringBuffer class:
1. public StringBuilder (): creates a string builder with no characters and with default capacity 16 i.e. it can contain 16 characters.
2. public StringBuilder (int capacity): creates a string builder with no characters and with specified capacity.
Note: capacity should not be less than zero , otherwise it will throw NegativeArraySizeException.
public StringBuilder (String str):creates a string builder with specified string as initial content.
Initial capacity = Default capacity + length of the string.
1. string should not be null otherwise it will throw NullPointerException.
2. if string length is equal to zero than string builder with no content and default capacity is return.
3. public StringBuilder (CharSequence charSquence):creates a string builder with specified character sequence as its initial content.
1. charSquence should not be null otherwise it will throw NullPointerException.
2. if charSquence length is equal to zero than string builder with no content and default capacity is return.
Commonly used methods of StringBuilder class:
Next Topic: append(String str) StringBuilder method in java.
Previous Topic: StringTokenizer in java.