The removeRange() method of Vector in Java is used to remove all elements within the specified range from an Vector object. It shifts any succeeding elements to the left. This call shortens the Vector by (toIndex-fromIndex) elements where toIndex is the ending index and fromIndex is the starting index within which all elements are to be removed. (If toIndex==fromIndex, this operation has no effect)
removeRange(int fromIndex, int toIndex)
Parameters: There are two parameters :
- fromIndex: starting index from which index elements are to be removed.
- toIndex: within range[fromIndex-toIndex), all elements are removed.
Return Value: This method does not return any value. It only removes all the elements within the specified range.
Exceptions: This method throws IndexOutOfBoundsException if fromIndex or toIndex is out of range (fromIndex = size() or toIndex > size() or toIndex < fromIndex)
// Therefore Vector is inherited
Vector before calling removeRange(): [Geeks, for, Geeks, Ankit, Mishra, MNNIT] Vector after calling removeRange(1, 3): [Geeks, Ankit, Mishra, MNNIT]
Vector before calling removeRange(): [Geeks, for, Geeks, Ankit, Mishra, MNNIT] java.lang.ArrayIndexOutOfBoundsException
Note:It is strongly recommended that if we want to call removeRange() method in any class then that class should necessarily extends Vector class either direct or indirect otherwise we will get compilation error : Method removeRange() has protected access.
- Stack removeRange() method in Java with Example
- Arraylist removeRange() in Java with examples
- Vector add() Method in Java
- Vector get() Method in Java
- Vector set() Method in Java
- Vector contains() Method in Java
- Vector lastIndexOf() Method in Java
- Vector setElementAt() method in Java with Example
- Vector removeAll() Method in Java
- Vector lastElement() Method in Java
- Vector addAll() Method in Java
- Vector removeAllElements() method in Java with Example
- Vector removeIf() method in Java
- Vector removeElementAt() Method in Java
- Vector remove() Method in Java
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.