Chapter 19.38 List method subList(from,to) returns a view of the list ranging fr
ID: 3713546 • Letter: C
Question
Chapter 19.38
List method subList(from,to) returns a view of the list ranging from positions from, inclusive, to to, exclusive. Add subList to the ArrayList implementation in Chapter 15 (you can either modify weiss.util.ArrayList or extend it in another package, or extend java.util.ArrayList). In the Java library, subList is written in terms of the List interface, but write yours in terms of ArrayList. You will need to de?ne a nested class SubList that extends ArrayList, and have subList return a reference to a new instance of SubList. To keep matters simple, have SubList maintain a reference to the primary ArrayList, store the size of the sublist, and store the offset into the primary ArrayList. You can also have all the mutators in the SubList throw an exception, so the returned sublist is in effect immutable. Your SubList class must itself provide an inner SubListIterator class that implements weiss.util.ListIterator. Test your code on the method in Figure 19.89. Observe that sublists can create sublists, that all refer to smaller portions of the same primary ArrayList. What is the running time of your code?
Explanation / Answer
===================================================================
THANKS, LET ME KNOW IF THERE IS ANY CONCERN. PLEASE UPVOTE if helpful
Run the code along with 19.38 Example
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.