hey guys, can someone tell me the difference between String, StringBuilder and StringBuffer in java? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

hey guys, can someone tell me the difference between String, StringBuilder and StringBuffer in java?

15th Oct 2016, 10:46 AM
Nareg
Nareg - avatar
2 Answers
+ 4
String represent character strings, ie text. Strings are immutable (you can't modify them). And as with any immutable object, it is thread-safe (ie no problem arising if several threads want to use a same String). StringBuffer and StringBuilder are like String, but can be modified. They have both the same methods, but the difference between the two lies in that all methods of StringBuffer are synchronized, resulting in StringBuffer being thread-safe. StringBuilder is not thread-safe, but is faster than StringBuffer as a result.
15th Oct 2016, 12:06 PM
Zen
Zen - avatar
+ 3
thank you!
15th Oct 2016, 6:23 PM
Nareg
Nareg - avatar