Home » Java programming language

Java Vector removeRange() Method with Example

Vector Class removeRange() method: Here, we are going to learn about the removeRange() method of Vector Class with its syntax and example.
Submitted by Preeti Jain, on March 19, 2020

Vector Class removeRange() method

  • removeRange() method is available in java.util package.
  • removeRange() method is used to remove all the elements lies in between starting index (st_index) and ending index (en_index) and st_index is inclusive whereas en_index is exclusive.
  • removeRange() method is a non-static method, it is accessible with the class object only and if we try to access the method with the class name then we will get an error.
  • removeRange() method does not throw an exception at the time of removing elements in a range.


    public void removeRange(int st_index , int en_index);


  • int st_index – represents the starting endpoint to remove.
  • int en_index – represents the ending endpoint to remove.

Return value:

The return type of the method is void, it returns nothing.


// Java program to demonstrate the example 
// of void removeRange(int st_index , int en_index)
// method of Vector 

import java.util.*;

public class RemoveRangeAtOfVector {
 public static void main(String[] args) {
  // Instantiates a Vector object  with
  // initial capacity of "10"
  Vector < String > v = new Vector < String > (10);

  // By using add() method is to add the
  // elements in this v

  // Display Vector 
  System.out.println("v: " + v);

  // By using removeRange(3,5) method is
  // to remove the element in the given range
  // and removing element starts at index 3 
  // and ends at index 5 but 5th index is exclusive
  // its a protected method so we are using subList instead
  v.subList(3, 5).clear();

  // Display updated vector
  System.out.println("v.removeRange(3,5): " + v);


v.removeRange(3,5): [C, C++, JAVA, ANDROID]

Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.