Question: // -- grow the array to requested capacity c, throw an exception if the requested // capacity c is smaller than the current size public

// -- grow the array to requested capacity c, throw an exception if the requested // capacity c is smaller than the current size public void ensureCapacity(int c) throws IllegalArgumentException;

I'm having trouble understanding how to write this

This is what I have so far

public void ensureCapacity(int c) throws IllegalArgumentException { if (size() >= data.length) { @SuppressWarnings("unchecked") T[] newData = (T[]) (new Object[size * 2 + 1]); System.arraycopy(data, 0, newData, 0, size); data = newData; } else { throw new IllegalArgumentException(); } }

Running code for Java

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!