When does StringBuffer adds strings to the String Pool?

前端 未结 4 1559
失恋的感觉
失恋的感觉 2020-12-20 10:19

When I define a StringBuffer variable with new, this string is not added to the String pool, right?

Now, when I define another String

4条回答
  •  长情又很酷
    2020-12-20 10:23

    buf.append("XXX") followed by buf.toString(), and then returning the string to the pool. With the pool in place, only one StringBuffer object is ever allocated.

提交回复
热议问题