Obtain a portion of a list by extracting a sublist.
import public |
The subList() method generates a new list, referred to as a sublist, comprising the items from the original list located between specified indices.
Please be aware that the item at the last index is excluded from the sublist.
Furthermore, it’s important to note that the sublist serves as a view of the original list, implying that any modifications made to the sublist will also affect the original list.
public |
Parameter |
Description |
start |
Necessary: The index indicating the beginning of the sublist. |
end |
Mandatory: The index marking the end of the sublist. The item at this position is not encompassed within the sublist. |
Returns: |
A fresh List comprising element from the original list. |
Throws: |
IndexOutOfBoundsException occurs if either index is less than zero or exceeds the list’s size. IllegalArgumentException is thrown if the end index is smaller than the start index. |
import public
|