Question: The generic class ArrayStack uses an array to implement a stack. The private method expandCapacity is used to create a new array of twice the
The generic class ArrayStack uses an array to implement a stack. The private method expandCapacity is used to create a new array of twice the capacity of the old one and copy the content of the old into the new array. It uses the Arrays.copyOf method to do its work.
Rewrite the expandCapacity method without using Arrays.copyOf or any other method. Create a new array of twice the capacity and write a for loop to copy the content of the old array into the new one.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
