what is the difference between String , StringBuilder & StringBuffer classes | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 8

what is the difference between String , StringBuilder & StringBuffer classes

26th Jan 2017, 6:03 PM
zixan sidd
zixan sidd - avatar
2 Answers
+ 3
You use String when an immutable structure is appropriate; obtaining a new character sequence from a String may carry an unacceptable performance penalty, either in CPU time or memory (obtaining substrings is CPU efficient because the data is not copied, but this means a potentially much larger amount of data may remain allocated). You use StringBuilder when you need to create a mutable character sequence, usually to concatenate several character sequences together. You use StringBuffer in the same circumstances you would use StringBuilder, but when changes to the underlying string must be synchronized (because several threads are reading/modifyind the string buffer).
26th Jan 2017, 6:09 PM
Virendra Singh Deora
Virendra Singh Deora - avatar
+ 2
i know that StringBuilder is faster than String but for more information visit oracle website
26th Jan 2017, 6:08 PM
abdulmalek dery
abdulmalek dery - avatar