Which of the following creates the string of the numbers from 1 to 1000 most efficiently?

a. String s;
for (int i = 1; i <= 1000; i++)
s += i;
b. StringBuilder sb = new StringBuilder(10);
for (int i = 1; i <= 1000; i++)
sb.append(i);
String s = new String(sb);
c. StringBuilder sb = new StringBuilder(3000);
for (int i = 1; i <= 1000; i++)
sb.append(i);
String s = new String(sb);
d. All are equivalently efficient.


c. StringBuilder sb = new StringBuilder(3000);
for (int i = 1; i <= 1000; i++)
sb.append(i);
String s = new String(sb);

Computer Science & Information Technology

You might also like to view...

What would the function cube return, assuming it is called with the line cube(3).

``` function cube( y ); { return y * y * y; } ``` a) JavaScript runtime error b) 3 c) 9 d) 27

Computer Science & Information Technology

A Word document is an example of a file

Indicate whether the statement is true or false

Computer Science & Information Technology

Ideally, the help desk should solve about the same number of tickets as they receive

Indicate whether the statement is true or false

Computer Science & Information Technology

When using database functions, the ________ argument is the entire dataset, including column labelsand all data, on which the function operates.

Fill in the blank(s) with the appropriate word(s).

Computer Science & Information Technology