StringBuffer SB = New StringBuffer (2004);
Sb.append ("-");
Sb.append (6);
Sb.append ("-");
Sb.append (14);
System.out.println (SB);
What do you guess?
"2004-6-14"
Wrong, output "-6-14"
We see StringBuffer overloaded Append (),
See the effect of append (int),
See New StringBuffer (String S)
Equivalent
{
?? StringBuffer SB = new stringbuffer ();
?? sb.append (s);
}
Just think New StringBuffer (INT N);
Equivalent to:
{
?? StringBuffer SB = new stringbuffer ();
?? sb.append (n);
}
In fact, it is not.
New StringBuffer (int N); represents a StringBuffer, and initializes its length to N,
It is still empty.
Take a look at the documentation:
??? / ** ????? * constructs a string buffer with no character, init,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, ?? length ?? The initial capacity. ???? * @Exception? NegativeAraysizeException? if the length ???? * ?????????????? argument is less 0.??? ? * /