Start learning free

LESSON 102 OF 671 · ARRAYS I

Acessing ArrayList elements in Java

Lesson

We can access the data inside an ArrayList using indexes and the .get() method.

ArrayLists also use zero-based indexing, so the first element in an ArrayList has an index of 0.

List<Integer> array = new ArrayList<>(List.of(50, 60, 70));

System.out.println(array.get(0)); // Output: 50

int data = array.get(1);
System.out.println(data); // Output: 60

Assignment
Follow the Coding Tutorial and let's play with some arrays.


Hint
Look at the examples above if you get stuck.


STEP 1 OF 3
    Ctrl + Enter to check