Question: 4. (a) Find a method of ArrayList that is not in the List interface, specifically a method that trims the internal array down to fit
4. (a) Find a method of ArrayList that is not in the List interface, specifically a method that trims the internal array down to fit exactly. A Google search for this did work, but the JDK API of course is the definitive source. For the homework answer, give the method header for the method.
(b) Add a call to this method to TestArrayList.java (which is available online), and see that it compiles and runs fine. Now change the line creating the ArrayList to use type List
(c) Explain why the compilation failed in this case. Note that this method is hardly ever used, and shows an example of a technical method related to the implementation that is excluded from the more abstract interface.
(d) Now remove the extra method, and see that the program compiles and runs with a variable of List type, object of type ArrayList (which IS A List), given that the methods in use in the program a real in the List interface. For the homework answer, just put Done.
(e) Finally, change the ArrayList to LinkedList, and see it work again. Explain why we are confident that this switch from ArrayList to LinkedList will work, given that the methods in use in the program are all in the List interface
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
