During a bit of careless typing (thinking?) when putting together the ADT for List, the boundary condition for uptoIndex in List.sublist() was given as uptoIndex < size. Below is the specification with the mistake. What are the implications of this? Why is this wrong?

sublist ( int fromIndex, int uptoIndex )
pre-condition: 0 ??fromIndex < size
0 ??uptoIndex < size
fromIndex ??uptoIndex
responsibilities: provide a sublist (“view”) of this list containing the elements in the positions
from fromIndex to uptoIndex – 1 inclusive. The sublist is backed by this list,
so changes made to the sublist change this list. Operations on the sublist are undefined if the list is structurally modified in any way except through the sublist
post-condition: this list is unchanged
throws: index out of bounds exception if pre-conditions are not met
returns: a List object containing the elements in the positions fromIndex to uptoIndex – 1, inclusive.


The method provides a sublist containing the elements in the positions from fromIndex to uptoIndex – 1 inclusive. Subtracting the one allows uptoIndex = size to be a valid condition. In this case, the last element of the list is not attainable in a sublist, as the highest value of uptoIndex would be size – 1, and subtracting one again in the method gives the list element at index size - 2.

Computer Science & Information Technology

You might also like to view...

OpenOffice Calc is an example of a ________ program

A) word processing B) spreadsheet C) database D) presentation

Computer Science & Information Technology

What are three purposes of a power supply? (Select three.)

A) Converts AC to DC B) Converts DC to AC C) Computer cooling D) Impedance matching E) CPU liquid cooling F) Distribute DC to the computer parts

Computer Science & Information Technology

Elements are added at one end of the queue, called the ____ or rear.

A. back B. head C. top D. middle

Computer Science & Information Technology

Which of the following is not a permanent storage option?

A. External hard drive B. Random access memory C. Internal hard drive D. SSD

Computer Science & Information Technology