ArrayList: Few More Operations
Let's discuss some operations that can be done in an ArrayList.
We'll cover the following
- Removing an element from an ArrayList
- Removing an element at a particular index
- Removing a particular element from the ArrayList
- Removing all the elements within a range
- Removing all the elements within a given Collection
- Removing all the elements from the ArrayList
- Replacing all the elements of the ArrayList
- Additional operations on ArrayList
Removing an element from an ArrayList
Elements can be removed from an ArrayList in the following ways.
Removing an element at a particular index
We can use the remove(int index)
method to remove an element at a particular index. The index should be less than the size of ArrayList, otherwise, IndexOutOfBoundsException
is thrown.