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...

Which of the following is TRUE about using database files as data sources in a mail merge?

A) Field names must be the same in the database file as in the Word document. B) Filtering data in a database should always be done in Word, not in Access. C) Information in a database is stored in tables. D) The newest Access version saves database files with a .mdb extension.

Computer Science & Information Technology

If a value is in the third row and fourth column, the cell reference would be R3C4

Indicate whether the statement is true or false.

Computer Science & Information Technology