Segment 2.12 of Chapter 2 gave the definition of the method toArray for the ADT bag, as follows:
public T[] toArray(){ // the cast is safe because the new array contains null entries @SuppressWarnings("unchecked") T[] result = (T[])new Object[numberOfEntries]; // unchecked cast for (int index = 0; indexAn alternate definition calls the method Arrays.copyOf and appears as follows:
public T[] toArray(){ return Arrays.copyOf(bag, bag.length);} // end toArrayCompare the execution times of these two methods for bags of various sizes.
We need at least 10 more requests to produce the solution.
0 / 10 have requested this problem solution
The more requests, the faster the answer.