Start learning free

LESSON 110 OF 671 · ARRAYS I

Remove Items From ArrayList in Java

Lesson

Another way to change the data in an ArrayList is with the .remove() method.

.remove() takes one parameter which represents an index and removes the element placed at that index:

List<Integer> threeArr = new ArrayList<>(List.of(1, 4, 6));

// Remove second element:
threeArr.remove(1);

// threeArray has now the value {1, 6}

// Remove first element:
threeArr.remove(0);

// threeArray has now the value {6}

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