Java ArrayList removeRange() method
The removeRange() method of Java ArrayList class removes all elements whose index lies between fromIndex -inclusive- and toIndex -exclusive, shifts an elements to the left and reduce their index.
If (fromIndex == toIndex) nothing will happen.
fromIndex: is the index of element to be removed.
toIndex: is the index after last the element to be removed.
java.lang.IndexOutOfBoundsException: If fromIndex or toIndex is out of range.
Example 1Test it Now
[A, B, C, D] [A, D] [A, D, X, Y, Z] [X, Y, Z]
Example 2Test it Now
[A, B, C, D]