Quantcast
Channel: Define StringBuilder capacity when number of characters is unknown - Stack Overflow
Viewing all articles
Browse latest Browse all 2

Define StringBuilder capacity when number of characters is unknown

$
0
0

I'm aware that, for good practice, StringBuilder should be initialised with a capacity value of the expected content. Otherwise, increasing the size after compilation is going to be an expensive operation.

My question is, if we don't know the expected size, how should one go about it? Is there a standard value/way to avoid expensive operations under the hood?

If not, is there potentially a way of alarming/logging in the code if the capacity is bigger than the value given upon initialisation?


Viewing all articles
Browse latest Browse all 2

Trending Articles





<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>