Question: Because a String is immutable, a String concatenation of the form str1+=str2 takes time that is proportional to the length of the resulting string, even

Because a String is immutable, a String concatenation of the form str1+=str2 takes time that is proportional to the length of the resulting string, even if str2 is very short. What is the running time of the code below, assuming that the array has N items?

public static String toString( Object [ ] arr ) { String result = " ["; for( String s : arr ) result += s + " "; result += "]"; return result; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!