Java LinkedList get() Method
Example
Output the value of an item in a list:
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.get(0));
}
}
Definition and Usage
The get() method returns the item at a specified position in the list.
Syntax
public T get(int index)
T refers to the data type of items in the list.
Parameter Values
| Parameter | Description |
|---|---|
| index | Required. Specifies the position of the item in the list. |
Technical Details
| Returns: | The item at the specified position. |
|---|---|
| Throws: | IndexOutOfBoundsException - If the index is less than zero, equal to the size of the list or greater than the size of the list. |
Related Pages
❮ LinkedList Methods