Quote Originariamente inviata da Gas75 Visualizza il messaggio
Quindi non c'è un criterio che rende prevedibile la capacità di uno StringBuilder?
Certo, è quello che ho postato prima!

Quote Originariamente inviata da Gas75 Visualizza il messaggio
Sulle API ho dato un'occhiata ma non ho trovato...
Sul javadoc È ben documentato. In https://docs.oracle.com/javase/8/doc...ngBuilder.html

All'inizio spiega il concetto generale:

Every string builder has a capacity. As long as the length of the character sequence contained in the string builder does not exceed the capacity, it is not necessary to allocate a new internal buffer. If the internal buffer overflows, it is automatically made larger.

Poi per il ensureCapacity(int minimumCapacity)

Ensures that the capacity is at least equal to the specified minimum. If the current capacity is less than the argument, then a new internal array is allocated with greater capacity. The new capacity is the larger of:

The minimumCapacity argument.
Twice the old capacity, plus 2.



Quote Originariamente inviata da Gas75 Visualizza il messaggio
'ste cose ai corsi non le insegnano
Probabilmente no. Ma sta a chi studia Java avere un minimo di "iniziativa personale" per documentarsi meglio magari andando anche a sbirciare tra i sorgenti del framework.