removerange_Java Vector removeRange()方法与示例

removerange

向量类别的removeRange()方法 (Vector Class removeRange() method)

  • removeRange() method is available in java.util package.

    removeRange()方法在java.util包中可用。

  • 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()方法用于删除起始索引(st_index)和结束索引(en_index)之间的所有元素,st_index为包含值,而en_index为排除值。

  • 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()方法是一个非静态方法,只能通过类对象访问,如果尝试使用类名称访问该方法,则会收到错误消息。

  • removeRange() method does not throw an exception at the time of removing elements in a range.

    removeRange()方法在删除范围中的元素时不会引发异常。

Syntax:

句法:

    public void removeRange(int st_index , int en_index);

Parameter(s):

参数:

  • int st_index – represents the starting endpoint to remove.

    int st_index –表示要删除的起始端点。

  • int en_index – represents the ending endpoint to remove.

    int en_index –表示要删除的结束端点。

Return value:

返回值:

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

该方法的返回类型为void ,不返回任何内容。

Example:

例:

// 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
  v.add("C");
  v.add("C++");
  v.add("JAVA");
  v.add("PHP");
  v.add("SFDC");
  v.add("ANDROID");

  // 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);
 }
}

Output

输出量

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


翻译自: https://www.includehelp.com/java/vector-removerange-method-with-example.aspx

removerange

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值