in JAVA by
What are the differences between String and StringBuffer?

1 Answer

0 votes

The differences between the String and StringBuffer is given in the table below.

String :

1) The String class is immutable.

2) The String is slow and consumes more memory when you concat too many strings because every time it creates a new instance.

3) The String class overrides the equals() method of Object class. So you can compare the contents of two strings by equals() method.

String Buffer:
  1. The StringBuffer class is mutable.
  2. The StringBuffer is fast and consumes less memory when you cancat strings.
  3. The StringBuffer class doesn't override the equals() method of Object class.

Related questions

0 votes
asked Feb 12, 2020 in JAVA by rahuljain1
0 votes
asked Dec 16, 2020 in JAVA by SakshiSharma