StringBuilder capacity()
问题 I noticed that the capacity method returns StringBuilder capacity without a logic way ... sometime its value is equals to the string length other time it's greater... is there an equation for know which is its logic? 回答1: When you append to the StringBuilder , the following logic happens: if (newCount > value.length) { expandCapacity(newCount); } where newCount is the number of characters needed, and value.length is the current size of the buffer. expandCapacity simply increases the size of