String plays major role in Java applications. Below table differentiates the String, StringBuffer and StringBuilder classes. And also address which class is suitable for which scenarios. StringBuilder is a class introduced in java 1.5 and we will see how it differs from String and StringBuffer.
String | StringBuffer | StringBuilder |
String object is immutable | StringBuffer is mutable | StringBuilder is mutable |
- | Synchronized | Unsynchronized |
Suitable for Single thread as well as Multithread | Suitable for Single thread as well as Multithread | If it is single thread application better to use StringBuilder instead of String and StringBuffer |
Not efficient compare to StringBuilder | Not efficient compare to StringBuilder | More efficient for single thread |
- | - | Unsynchronized so it should be faster than String and StringBuilder |



0 comments:
Post a Comment