UrbanPro

Learn Java Training from the Best Tutors

  • Affordable fees
  • 1-1 or Group class
  • Flexible Timings
  • Verified Tutors

Search in

What is the difference between string, stringbuffer, stringbuilder?

Asked by Last Modified  

22 Answers

Learn Java

Follow 1
Answer

Please enter your answer

Java Trainer

String is immutable, means once you created a String you can not modify, Even if you try to it will create a new string for you and assign that to you. StringBuffer and StringBuilder are immutable, however methods of String buffer are thread safe, So when you are having multithreading in you application...
read more
String is immutable, means once you created a String you can not modify, Even if you try to it will create a new string for you and assign that to you. StringBuffer and StringBuilder are immutable, however methods of String buffer are thread safe, So when you are having multithreading in you application you should use StringBuffer otherwise StringBuilder. read less
Comments

Senior Software Engineer

String is immutable, if you try to alter their values, another object gets created, whereas StringBuffer and StringBuilder are mutable so they can change their values. Thread-Safety Difference: The difference between StringBuffer and StringBuilder is that StringBuffer is thread-safe. So when the...
read more
String is immutable, if you try to alter their values, another object gets created, whereas StringBuffer and StringBuilder are mutable so they can change their values. Thread-Safety Difference: The difference between StringBuffer and StringBuilder is that StringBuffer is thread-safe. 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. Situations: If your string is not going to change use a String class because a String object is immutable. If your string can change (example: lots of logic and operations in the construction of the string) and will only be accessed from a single thread, using a StringBuilder is good enough. If your string can change, and will be accessed from multiple threads, use a StringBuffer because StringBuffer is synchronous so you have thread-safety. read less
Comments

Trainer

String is immutable, i.e. once a String object is created and its value is assigned, its value can not be changed. This is because the String object is stored in Constant String Pool. If you assign a new value to a String reference variable, a new String object is created and stored in Constant String...
read more
String is immutable, i.e. once a String object is created and its value is assigned, its value can not be changed. This is because the String object is stored in Constant String Pool. If you assign a new value to a String reference variable, a new String object is created and stored in Constant String Pool. Alternatively we can use String Buffer and String Builder which are mutable. It means their values can be changed after they have been created as they are stored in heap. The difference between StringBuffer and String Builder are given below: 1) StringBuffer is synchronised whereas StringBuilder is not synchronised 2) StringBuffer is thread safe whereas StringBuilder is not thread safe. 3) StringBuffer is slow in performance whereas StringBuilder is faster. read less
Comments

12 years of MNC company work experience on java ,J2ee technologies

String is immutable and StringBuffer and StringBuilder are mutable. StringBuffer is synchronized i.e. thread safe. It means two threads can't call the methods of StringBuffer simultaneously. StringBuilder is non-synchronized i.e. not thread safe. It means two threads can call the methods of StringBuilder...
read more
String is immutable and StringBuffer and StringBuilder are mutable. StringBuffer is synchronized i.e. thread safe. It means two threads can't call the methods of StringBuffer simultaneously. StringBuilder is non-synchronized i.e. not thread safe. It means two threads can call the methods of StringBuilder simultaneously. read less
Comments

5+ years of Experience into Java Development and Training

String ---Immutable --not thread safe StringBuffers---Mutable ---thread safe StringBuilder---Mutable---Not thread safe. Each time you change a string objects value, new object will get created in the memory and reference starts referring the new object. But for StringBuffer and Buider the existing...
read more
String ---Immutable --not thread safe StringBuffers---Mutable ---thread safe StringBuilder---Mutable---Not thread safe. Each time you change a string objects value, new object will get created in the memory and reference starts referring the new object. But for StringBuffer and Buider the existing object will get changed. No new memory gets allocated. read less
Comments

Java Trainer with 6+ years of experience in big MNCs

String eats up the heap memory especially when there are modifications made and hence suggested not to be used in such scenarios.
Comments

Java Web Application Development and Aptitude Trainer

String object are immutable, whereas StringBuffer and String Builder are mutable. Between StringBuffer and StringBuilder, the former is synchronized, hence providing thread safety, while the later is not synchronized, therefore should not be used in case of multithreading.
Comments

Java Tutor

String is an immutable class , whereas StringBuffer is a synchronized mutable class so it is thread safe and StringBuilder is non-synchronized mutable class.
Comments

Software Testing Trainer(Automation)

String does not has append,insert,capacity and replace methods but in StringBuffer and StringBuilder has,String is thread safe since its immutable,StringBuffer is also thread safe since all methods are synchronized but StringBuilder is not thread safe
Comments

Trainer

String is immutable, if you try to alter their values, another object gets created, whereas StringBuffer and StringBuilder are mutable so they can change their values. Thread-Safety Difference: The difference between StringBuffer and StringBuilder is that StringBuffer is thread-safe.
Comments

View 20 more Answers

Related Questions

Is Java a compiler or Interpreter?
Java is a programming language and computing platform first released by Sun Microsystems in 1995. A Java compiler is a compiler for the Java programming language. A JVM interprets bytecode and...
Dr Rakesh
Can finally block be used without try block?
No. But it can be used without a catch block.
Sarala
What is the use of the "this" keyword in Java?
'this' refer the current instance of a class. You can get and set data members of current object using 'this' prefix inside there class data type.
Deepak
0 0
9
What are the differences between Class Methods and Instance Methods in Java?
Class methods are static methods in java. The method can be called without creating an instance of the class.For e.g, main method is declared static that is why we are able to call main method without...
Neval
0 0
5
What is JavaBean?
All javabeans are pojos ,But not all pojos are not javabeans.
Ankit
0 0
6

Now ask question in any of the 1000+ Categories, and get Answers from Tutors and Trainers on UrbanPro.com

Ask a Question

Related Lessons

Software Testing
Software testing is a process of executing a program or application with the intent of finding the software bugs. It can also be stated as the process of validating and verifying that a software program...

Class and Objects in Java
Class is a template or a blueprint which is used to describe an object. On other hand Object is a reference of a class which follows all the stuff written inside the class. How about taking the whole tour in the following video

What is a Programming Language
What is a Language? Language is a communication system of human. What is a programming Language? A programming Language is a formal constructed language design to communicate...

Understanding concept of Inheritance in Java
Inheritance: Acquiring a properties and methods from Parent class to Child class. For example, In some cases we can hear from any one of your relative or your friends will say like that "You are bahaving...

Easy way to remember Java keyword.
ACCESS MODIFIER ACCESS SPECIFIER abstract, assert, const, final, native, static, strictfp, super, synchronized, this, transient, void, volatile public, private, protected, default DATA...

Rohit Deshbhratar

1 0
0

Recommended Articles

In the domain of Information Technology, there is always a lot to learn and implement. However, some technologies have a relatively higher demand than the rest of the others. So here are some popular IT courses for the present and upcoming future: Cloud Computing Cloud Computing is a computing technique which is used...

Read full article >

Before we start on the importance of learning JavaScript, let’s start with a short introduction on the topic. JavaScript is the most popular programming language in the world, precisely it is the language - for Computers, the Web, Servers, Smart Phone, Laptops, Mobiles, Tablets and more. And if you are a beginner or planning...

Read full article >

Java is the most famous programming language till date. 20 years is a big time for any programming language to survive and gain strength. Java has been proved to be one of the most reliable programming languages for networked computers. source:techcentral.com Java was developed to pertain over the Internet. Over...

Read full article >

Designed in a flexible and user-friendly demeanor, Java is the most commonly used programming language for the creation of web applications and platform. It allows developers to “write once, run anywhere” (WORA). It is general-purpose, a high-level programming language developed by Sun Microsystem. Initially known as an...

Read full article >

Looking for Java Training Classes?

Learn from the Best Tutors on UrbanPro

Are you a Tutor or Training Institute?

Join UrbanPro Today to find students near you
X

Looking for Java Training Classes?

The best tutors for Java Training Classes are on UrbanPro

  • Select the best Tutor
  • Book & Attend a Free Demo
  • Pay and start Learning

Learn Java Training with the Best Tutors

The best Tutors for Java Training Classes are on UrbanPro

This website uses cookies

We use cookies to improve user experience. Choose what cookies you allow us to use. You can read more about our Cookie Policy in our Privacy Policy

Accept All
Decline All

UrbanPro.com is India's largest network of most trusted tutors and institutes. Over 55 lakh students rely on UrbanPro.com, to fulfill their learning requirements across 1,000+ categories. Using UrbanPro.com, parents, and students can compare multiple Tutors and Institutes and choose the one that best suits their requirements. More than 7.5 lakh verified Tutors and Institutes are helping millions of students every day and growing their tutoring business on UrbanPro.com. Whether you are looking for a tutor to learn mathematics, a German language trainer to brush up your German language skills or an institute to upgrade your IT skills, we have got the best selection of Tutors and Training Institutes for you. Read more