How is StringBuffer implementing append function without creating two objects?

后端 未结 10 1217
执念已碎
执念已碎 2021-01-30 09:22

It was an interview question. I was asked to implement the StringBuffer append function. I saw the code after the interview. But I cannot understand how the operati

10条回答
  •  野性不改
    2021-01-30 10:03

    String is immutable. Appending a string can only generate a new string.

    StringBuilder is mutable. Appending to a StringBuilder is an in-place operation, like adding to an ArrayList.

提交回复
热议问题