DEV Community

velvizhi Muthu
velvizhi Muthu

Posted on

Module 5-StringBuffer and StringBuilder

01.What is StringBuffer?
1.StringBuffer is a Class
2.StringBuffer is a java.lang Package.
3.Thread safe
4.Synchronized
5.Java JDK -1.0
6.Slower
7.StringBuffer is a mutable.
8.StringBuilder is a final class and we can't inherit the class.
9.We can create the empty argument in object and no need to import the .lang Package.

02.Advantage of StringBuffer?
1.Less Memory Waste
2.Better than String in Loops

03.DisAdvantage of StringBuffer?
1.Slower than
2.Complexity
3.Extra Memory Allocation

04.What are the Methods StringBuilder?

append(boolean) → Adds text at the end.

Appends the string representation of the boolean argument to the sequence.
Overrides: append(...) in AbstractStringBuilder
Parameters:
b a boolean.
Returns:
a reference to this object.

Capacity() → memory size

Returns the current capacity.
The capacity is the number of characters that can be stored (including already written characters), beyond which an allocation will occur.

insert(int offset, String str) → Inserts text at a given position.

replace(int start, int end, String str) → Replaces characters between positions.

delete(int start, int end) → Deletes characters between positions.

reverse() → Reverses the sequence of characters.

toString() → Converts it back into a String.

05.What are the Non Primitive data types?
1.String
2.StringBuilder
3.StringBuffer

06.What is StringBuilder?
1.StringBuilder is a Class
2.StringBuilder is a java.lang Package.
3.Non -Thread safe
4.Not Synchronized
5.Java JDK -1.5
6.Faster
7.StringBuilder is a mutable sequence of characters.

07.Advantage of StringBuilder?
1.Mutable Strings
2.Better Performance
3.Efficient Memory Usage

08.Disadvantage of StringBuilder?
1.Not Thread-Safe
2.Memory Allocation
3.Conversion Needed

09.What are the Methods of the StringBuilder?
append(String str) → Adds text to the end.

insert(int offset, String str) → Inserts text at a given position.

replace(int start, int end, String str) → Replaces characters between positions.

delete(int start, int end) → Deletes characters between positions.

reverse() → Reverses the sequence of characters.

toString() → Converts it back to a String.

Top comments (0)