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.
Correct Answer:
Verified
Q1: A String constructor cannot be passed _.
A)char
Q5: Consider the examples below:
A. a string.
B.
Q7: Which of the following is not a
Q7: Consider the statement below:
StringBuilder sb1 = new
Q8: The statement
S1)equalsIgnoreCase(s4)
Is equivalent to which of the
Q10: Which of the following will create a
Q14: Given the following declaration:
StringBuilder buf =
Q15: StringBuilder objects can be used in place
Q18: String objects are immutable. This means they
Q19: Given the following declarations:
StringBuilder buffer =
Unlock this Answer For Free Now!
View this answer and more for free by performing one of the following actions
Scan the QR code to install the App and get 2 free unlocks
Unlock quizzes for free by uploading documents