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).
Following is the declaration of removeRange() method:
This method does not return anything. It only removed the specified range of an element from the vector.
IndexOutOfBoundsException- This method has thrown an exception if the index of an array is out of range i.e. (index < 0 || index >= size()).
Java 1.2 and above
Example 1Test it Now
Vector element before removal: [9, 8, 7, 6, 5] Vector element after removal: [9, 6, 5]
Example 2Test it Now
Vector elements: [w, e, l, l, d, c, o, m, e] Vector elements after removal: [w, e, l, c, o, m, e]