Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
Even better using
new StringBuilder(initialLength)
constructor since final string length is predictable to avoid memory copy when internal buffer is exhaustedthank you!
String string = "";
for (int i = 1; i <= num; i++) {
string += i + " sheep...";
}
This method creates a new String object each time "string += " is called, but only one object is referenced by the variable. The unused objects are stored until they get deleted at the end. StringBuilder remains one object the whole time and reduces RAM use.
Why is using stringBuilder considered best practice?