What is the output of the following?
StringBuilder teams = new StringBuilder("001"); teams.append(" 002"); teams.append(" 1234"); System.out.print(teams);
B.
Since StringBuilder is mutable, each call to append adds to the value.
When calling print, toString()
is automatically called and 001 002 1234 is output.
Option B is correct.