Difference between StringBuilder and StringBuffer class.

Explain the difference between StringBuilder and StringBuffer class.

StringBuilder is unsynchronized whereas StringBuffer is synchronized. So when the application needs to be run only in a single thread then it is better to use StringBuilder. StringBuilder is more efficient than StringBuffer.

What is the difference between StringBuffer and String class?

String class objects are immutable. They can not be changed and read only.

The StringBuffer class objects are mutable. They can be changed.

The difference between these two classes is StringBuffer is faster than String at the time of concatenating strings. To concatenate a string to another string object, '+' sign is used. In this process, an intermediately string object is created and to be stored in one string object whereas using StringBuffer, it just joins / concatenates the new string to the existing string.
Java semaphore and monitors
Java semaphore and monitors - A semaphore is a flag variable used to check whether a resource is currently being used by another thread or process...
What are Checked and UnChecked Exception?
Java checked and unchecked exception - The java.lang.Throwable class has two subclasses Error and Exception. There are two types of exceptions...
Java inner classes: What are different types of inner classes?
Java inner classes - Types of inner classes - Local classes, Member classes, Anonymous classes...
Post your comment