Question: The actual ArrayList class in the java .util package has a method called subList that returns a view of a subportion of a list through

The actual ArrayList class in the java .util package has a method called subList that returns a view of a subportion of a list through a given range of indexes. It can be useful to think of part of a list as if it were its own list, complete with its own set of indexes and values. The sublist is “backed” by the original list, meaning that it is not a copy; if any change is made to the sublist, the original list is also affected. In order to implement this method, you will need to write an inner class inside ArrayList that extends ArrayList and implements the behavior of the sublist. Override the methods for getting and setting values at particular indexes, as well as the size method, so that they reflect the sublist’s index range and size. Also, modify the outer ArrayList class so that it always refers to its own elements through the use of these methods. The outer class should be given the following new method that returns an object of your new inner sublist class:

public ArrayList subList (int fromIndex, int toIndex)

public ArrayList subList (int fromIndex, int toIndex)

Step by Step Solution

3.39 Rating (171 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

ArrayList subList method in Java with Examples The subList method of javautilArrayList class is used to return a view of the portion of this list between the specified fromIndex inclusive and toIndex ... View full answer

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

Document Format (2 attachments)

PDF file Icon

2079_60f58f34f2b08_857015.pdf

180 KBs PDF File

Word file Icon

2079_60f58f34f2b08_857015.docx

120 KBs Word File

Students Have Also Explored These Related Building Java Programs A Back to Basics Approach Questions!