本文共 2145 字,大约阅读时间需要 7 分钟。
removerange
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]
翻译自:
removerange
转载地址:http://wsvzd.baihongyu.com/