Strings are immutable - that means I should never use += and only StringBuffer?

前端 未结 11 1500
醉梦人生
醉梦人生 2021-01-04 08:12

Strings are immutable, meaning, once they have been created they cannot be changed.

So, does this mean that it would take more memory if you append things with += th

11条回答
  •  旧巷少年郎
    2021-01-04 08:50

    Yes. String is immutable. For occasional use, += is OK. If the += operation is intensive, you should turn to StringBuilder.

提交回复
热议问题