Start learning free

LESSON 104 OF 671 · ARRAYS I

Arrays in Java

Lesson

The entries of ArrayLists are mutable and can be changed freely, using indices and the .set() method:

.set() takes two parameters which represent an index and a value and changes the element placed at that index with the argument value:

List<Integer> numbers = new ArrayList<>(List.of(50, 40, 30));

numbers.set(0, 15);
numbers.set(2, -1);

// numbers is now [15, 40, -1]

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 2
    Ctrl + Enter to check