Javatpoint Logo
Javatpoint Logo

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.

Syntax:

Parameter:

fromIndex: is the index of element to be removed.

toIndex: is the index after last the element to be removed.

Return:

Nothing.

Exception:

java.lang.IndexOutOfBoundsException: If fromIndex or toIndex is out of range.

Example 1

Test it Now

Output:

[A, B, C, D]
[A, D]
[A, D, X, Y, Z]
[X, Y, Z]

Example 2

Test it Now

Output:

[A, B, C, D]

Next TopicJava ArrayList




Youtube For Videos Join Our Youtube Channel: Join Now

Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA