Java ArrayListget() Method
Example
Output the value of an item in a list:
import java.util.ArrayList;public class Main { public static void main(String[] args) { ArrayList<String> cars = new ArrayList<String>(); cars.add("Volvo"); cars.add("BMW"); cars.add("Ford"); cars.add("Mazda"); System.out.println(cars.get(0)); } }Definition and Usage
Theget() method returns the item at a specified position in the list.
Syntax
public T get(intindex)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
❮ ArrayList Methods

