What are the differences between a String and a StringBuilder?

String:

  • Strings are immutable
  • A new instance of string is returned when each time a string manipulation occurs

StringBuilder:

  • StringBuilder is mutable
  • an ArrayList of strings are maintained internally, and are added or updated based on the operations performed.
  • no new instance is created and a single string is returned when we call the ToString() method

String:

  • Strings are immutable
  • A new instance of string is returned when each time a string manipulation occurs

StringBuilder:

  • StringBuilder is mutable
  • an ArrayList of strings are maintained internally, and are added or updated based on the operations performed.
  • no new instance is created and a single string is returned when we call the ToString() method
Default image
Sriram Mannava

I'm a full-stack developer and a software enthusiast who likes to play around with cloud and tech stack out of curiosity.

Leave a Reply