bugl
bugl
HomeLearnPatternsPathsSearch
HomeLearnPatternsPathsSearch

Loading lesson path

Learn/Java/Java Reference
Java•Java Reference

Java ArrayList get() Method

Flash cards

Review the key moves

1/4
Core idea

What is the main idea behind Java ArrayList get() Method?

Lesson checks

Practice each idea before moving on

Short Mimo-style checks built from this lesson's code, terms, and sequence.

1Quick choice

Which statement best captures the main point of this lesson?

2Fill blank

Complete the missing token from the example code.

___ java.util.ArrayList;
3Order

Put the learning moves in the order that makes the concept easiest to apply.

The get() method returns the item at a specified position in the list.
Definition and Usage
Java ArrayList get() Method

❮ ArrayList Methods

Example

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

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

ParameterDescription
indexRequired. 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.

Previous

Java ArrayList forEach() Method

Next

Java ArrayList indexOf() Method