Tell me some difference between String builder and String buffer?

kiranq
kiranq

Posted On: Apr 08, 2020

 

Differences between String builder and String buffer in Java

  • StringBuffer is synchronized that is, thread-safe. It indicates that two threads may not describe the practices of StringBuffer concurrently. Whereas StringBuilder is non-synchronized which means that it is not thread-safe. It indicates that two threads may describe the processes of StringBuilder concurrently.
  • Again, StringBuffer is less effective than StringBuilder. Whereas StringBuilder is more effective than StringBuffer.
  • StringBuffer had been the single option for String administration till Java 1.4 but it produces one problem that each of its common methods is synchronized. Thus, StringBuffer produces Thread safety but on production value.
  • Mostly, we do not apply String in a multithreaded situation, so Java 1.5 launched a distinct type StringBuilder that is alike to StringBuffer except for synchronization and thread-safety.

    Related Questions

    Please Login or Register to leave a response.

    Related Questions

    Cognizant Java Interview Questions

    What is a Singleton in Java?

    Singleton class in Java contains only one object at one time. For the designing of the singleton class, the construction needs to be private. The static method needs to be written to return the object...

    Cognizant Java Interview Questions

    Is Java supports multiple inheritance?

    When one class extends for more than one class, then it is known as multiple inheritance. No, Java does not support multiple inheritance to prevent the ambiguity that it can cause. The diamond proble...

    Cognizant Java Interview Questions

    What is JPA and Junit?

    JPA or Java Persistence API is a mechanism through which JAVA can outlive the application processes that have created them. JPA allows you to define which objects are persisted and how they should be ...