According to java doc, I got this idea:
StringBuilder(int length) in java ,creates an empty string Builder with the specified capacity as length.
I tried the code below:
StringBuilder sb = new StringBuilder(9);
But I can append length more than 9.
sb.append("123456789123456789123456789123456789123456789123456789");
What is the meaning of assign this length?
StringBuilder; it just means that it reserves space for 9 characters when you create theStringBuilder. When you put in more characters, it will grow automatically. The capacity is not fixed to what you pass the constructor, it's just the initial capacity.