Java Vector removeRange() Method

The removeRange() method of Java Vector class is used to delete all elements from the vector whose index is between fromIndex, inclusive and toIndex, exclusive. The removal of elements shifts any succeeding elements to the left (reduces their index).

Syntax

Following is the declaration of removeRange() method:

Parameter

DataTypeParameterDescriptionRequired/Optional
intfromIndexIt is an index of the first element which will be removed.Required
inttoIndexIt is an index after the last element which will be removed.Required

Return

This method does not return anything. It only removed the specified range of an element from the vector.

Exceptions

IndexOutOfBoundsException- This method has thrown an exception if the index of an array is out of range i.e. (index < 0 || index >= size()).

Compatibility Version

Java 1.2 and above

Example 1

Test it Now

Output:

Vector element before removal: [9, 8, 7, 6, 5]
Vector element after removal: [9, 6, 5]

Example 2

Test it Now

Output:

Vector elements: [w, e, l, l, d, c, o, m, e]
Vector elements after removal: [w, e, l, c, o, m, e]





Latest Courses