String vs StringBuffer vs StringBuilder

The most important question in interviews is when to use String, StringBuffer and StringBuilder.
  1. If the content is fixed and do not change frequently , then we need to use String objects.
  2. If the content is not fixed but thread safety is required, the we need to use StringBuffer Objects.
  3. If the content is not fixed and thread safety is not required, then we can use StringBuilder objects.

Refer:

What is the difference between StringBuffer and StringBuilder?
What is the difference between String and String Buffer?

No comments:

Post a Comment