String, StringBuffer, and StringBuilder

后端 未结 11 1525
谎友^
谎友^ 2020-11-22 13:52

Please tell me a real time situation to compare String, StringBuffer, and StringBuilder?

11条回答
  •  Happy的楠姐
    2020-11-22 14:17

    Difference between String and the other two classes is that String is immutable and the other two are mutable classes.

    But why we have two classes for same purpose?

    Reason is that StringBuffer is Thread safe and StringBuilder is not. StringBuilder is a new class on StringBuffer Api and it was introduced in JDK5 and is always recommended if you are working in a Single threaded environment as it is much Faster

    For complete Details you can read http://www.codingeek.com/java/stringbuilder-and-stringbuffer-a-way-to-create-mutable-strings-in-java/

提交回复
热议问题