what is the difference between string and stringbuffer
Attachments:
Answers
Answered by
2
1)String class is immutable.
2)String is slow and consumes more memory when you concat too many strings because
every time it creates new instance.
3)String class overrides the equals() method of Object class. So you can compare the contents of two strings by equals() method.
spring buffer
StringBuffer class is mutable.
StringBuffer is fast and consumes less memory when you cancat strings.
StringBuffer class doesn't override the equals() method of Object class.
2)String is slow and consumes more memory when you concat too many strings because
every time it creates new instance.
3)String class overrides the equals() method of Object class. So you can compare the contents of two strings by equals() method.
spring buffer
StringBuffer class is mutable.
StringBuffer is fast and consumes less memory when you cancat strings.
StringBuffer class doesn't override the equals() method of Object class.
Similar questions
Math,
7 months ago
India Languages,
7 months ago
English,
1 year ago
Math,
1 year ago
English,
1 year ago