Flash cards
Review the key moves
What is the main idea behind Java LinkedList subList() Method?
Lesson checks
Practice each idea before moving on
Short Mimo-style checks built from this lesson's code, terms, and sequence.
Which statement best captures the main point of this lesson?
Complete the missing token from the example code.
___ java.util.LinkedList;Put the learning moves in the order that makes the concept easiest to apply.
❮ LinkedList Methods
Example
import java.util.LinkedList;
public class Main {
public static void main(String[] args) {
LinkedList<String> cars = new LinkedList<String>();
cars.add("Volvo");
cars.add("BMW");
cars.add("Ford");
cars.add("Mazda");
System.out.println( cars.subList(1, 3) );
}
}Definition and Usage
The subList() method returns a new list (referred to as a sublist ) which contains the items of the list between two indices.
Note
The item at the last index is not included in the sublist.
Note
The sublist is a view of the original list, which means that changing the sublist also changes the original list.
Syntax
public List sublist(int
start , int
end )Parameter Values
| Parameter | Description |
|---|---|
| start | Required. The index where the sublist starts. |
| end | Required. The index where the sublist ends. The item at this position is not included in the sublist. |
Technical Details
| Returns: | A new List containing elements of the list. |
|---|---|
| Throws: | IndexOutOfBoundsException - If one of the indices is less than zero or greater than the size of the list. IllegalArgumentException - If end index is less than the start index. |