Data Structures

ArrayList: Access

Great! Now we can start accessing the temperatures that our ArrayList stores.

We can access the elements of weeklyTemperatures by using an element's index, or position, in the list.

An element's index refers to its location within an ArrayList. ArrayLists in Java are zero-indexed, which means that the first element in an ArrayList is at a position of 0.

Here is an example of accessing the element in the first position of the list:

ArrayList<Integer> quizGrades = new ArrayList<Integer>();

System.out.println( quizGrades.get(0) );

The example above will print out the grade value of 95.

The index of the element containing the value 95 is at position 0 in the ArrayList. We access the value by providing its index to the get method.

Community Forums
Get help and ask questions in the Codecademy Forums
Report a Bug
If you see a bug or any other issue with this page, please report it here.