+ 1

Difference between string and string builder.

2nd Aug 2016, 5:42 PM
vasu
vasu - avatar
4 odpowiedzi
+ 1
we are going to understand the difference between String , StringBuilder and StringBuffer : String is immutable (once created can not be changed)object . The object created as a String is stored in the Constant String Pool . StringBuffer is mutable means one can change the value of the object . The object created through StringBuffer is stored in the heap . StringBuffer has the same methods as the StringBuilder , but each method in StringBuffer is synchronized that is StringBuffer is thread safe . StringBuilder is same as the StringBuffer , that is it stores the object in heap and it can also be modified . The main difference between the StringBuffer and StringBuilder is that StringBuilder is also not thread safe. StringBuilder is fast as it is not thread safe . hope can help you .
3rd Aug 2016, 7:30 AM
Mohammad Reza Karimi
Mohammad Reza Karimi - avatar
0
yaa I corrected my mistake
4th Aug 2016, 7:10 AM
Sumit Tyagi
Sumit Tyagi - avatar
- 1
Sumit is mostly right. StringBuilder is not synchronized. It is StringBuffer which is synchronized. https://docs.oracle.com/javase/7/docs/api/java/lang/StringBuilder.html
2nd Aug 2016, 11:28 PM
Chris
Chris - avatar
- 2
String is immutable , StringBuilder is mutable and nonSynchronized and there is one more term StringBuffer which is same as StringBuilder but is Synchronised . immutable means you can't modify it and Synchronized means its thread safe though StringBuilder is faster than StringBuffer.
2nd Aug 2016, 6:15 PM
Sumit Tyagi
Sumit Tyagi - avatar