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

Each item in a list box is identified by an index number. The first item in the list is assigned which of the following values as an index?

(A) a randomly assigned value (B) 1. (C) a value initially designated by the programmer (D) 0

Computer Science & Information Technology

Which of the following steps should be taken by companies to protect against cyber terrorist and computer espionage attacks?

A) Ensure that network systems are as secured as possible B) Conduct background checks on all network administrators and security personnel C) Report any intrusions to the appropriate law enforcement agency D) All of the above

Computer Science & Information Technology

A(n) ____________________ associates the value of an attribute with a declaration that is inserted elsewhere in the DTD.

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

Computer Science & Information Technology

The Magic Wand Tool options bar has a ____ box that allows you to enter a value that determines the similarity or difference in the color of the selected pixels.

a. Color b. Contrast c. Tolerance d. none of the above

Computer Science & Information Technology