Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Question. (a) Find a method of ArrayList that is not in the List interface , specififically a method that trims the internal array down to

Question.

(a) Find a method of ArrayList that is not in the List interface, specififically a method that trims the internal array down to fifit exactly. A Google search for this did work, but the JDK API of course is the defifinitive source. For the answer, give the method header for the method.

(b) Add a call to this method to TestArrayList.java (https://liveexample.pearsoncmg.com/html/TestArrayList.html), and see that it compiles and runs fine. Now change the line creating the ArrayList to use type Listfor its variable (List array = ...), and add the needed import for List. What happens when you try to compile this new version? For the question answer, give the output.

(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 ISA List), given that the methods in use in the program are all in the List interface. For the answer, just put Done.

(e) Finally, change the ArrayList to LinkedList, and see it work again. Explain why we are confifident 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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Knowledge Discovery In Databases

Authors: Gregory Piatetsky-Shapiro, William Frawley

1st Edition

ISBN: 0262660709, 978-0262660709

More Books

Students also viewed these Databases questions

Question

Why did you want to work in HR?

Answered: 1 week ago