Java 8 | ArrayList 2

Student Kim
Buzz Code
Published in
2 min readFeb 17, 2021

--

Hey guys! I know I told you that I’m going to bring some practice questions today, but I think it’d be better If I show you some more of the methods that you can use on the ArrayList.

Checkout my last post before we go!

(1) add() method 2

If we use the add() method like the last time, it will add the index at the end of the ArrayList, for instance,

I added the word grape with using add() method, and you can see there’s the word grape at the index 2. What if I wanted to put the word at the index 1 without delete any indexes? Here can also use the add() method.

Like this, you can set the number of the index so you can put the value in it.

(2) set() method

With the set() method you can modify the value in the index.

Like this, put the number of the index at the first parameter, and the modified value at the second parameter.

(3) removeAll() method

And for the last, removeAll() method can remove all the indexes in the ArrayList. You only need to put the whole list as a parameter.

That’s all for today guys! Thank you for reading my post again, see you next time!

--

--