1. The trimToSize method should handle these cases: (1) If the length of the array is already equal to the number of items, then do no work; (2) if the number of items is zero, then change data to an array of capacity zero and return with no other work; (3) if (front<=rear),>rear), then allocate a new array of the correct size and activate System.arraycopy twice to copy the two segments into the new array.
The fourth case is similar to the final case of ensureCapacity. If you copy the items into the front of the new array, then make sure you also change front and rear to reflect the new positions of the items.
Already registered? Login
Not Account? Sign up
Enter your email address to reset your password
Back to Login? Click here