We Exist to Provide 100% Free Source Code and Tutorials

Custom Search

Difference between String class and String Buffer/ String Builder class in Java


Subject: In this post we will learn , difference between String class and String Buffer/ String Builder class in Java.

  1. String objects are immutable while String Buffer objects are mutable.
    String temp1=” Rahul”;
    String temp1=”Rahul”+”Tiwari” ;
    Here, output will be Rahul Tiwari. But two objects will be created.
  2. In String class, toString, equals and hashcode methods are overridden while in String Buffer only toString method is overridden.
  3. String objects can be sorted because String class implements comparable interface while String Buffer objects cant be sorted.
  4. We can create String object without using new operator but we have to use new operator for creation of String Buffer/ String Builder objects.
    String temp1=”Rahul”;
    No need of new operator. A new object is created.
  5. String and String Builder class is non synchronized while String Buffer class is synchronized.
Facebook Comments
(Visited 1 times, 1 visits today)
Share this

Check Your Domain Ranking

Leave a Reply

Your email address will not be published. Required fields are marked * © 2016 Frontier Theme

Subscribe For Latest Updates

Signup for our newsletter and get notified when we publish new articles for free!

%d bloggers like this: