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

前端 未结 11 1529
醉梦人生
醉梦人生 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:54

    Rule of thumb is simple:

    If you are running concatenations in a loop, don't use +=

    If you are not running concatenations in a loop, using += simply does not matter. (Unless a performance critical application

提交回复
热议问题