集册 Java实例教程 从指定的向量索引中删除元素

从指定的向量索引中删除元素

欢马劈雪     最近更新时间:2020-01-02 10:19:05

344
提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
从Vector的指定索引中删除一个元素

 

import java.util.Vector;// 来 自 N o  w  J a v a . c o m - 时  代  Java

 

public class Main {

  public static void main(String[] args) {

    Vector v = new Vector();

    v.add("1");

    v.add("2");

    v.add("3");

    v.add("4");

    v.add("5");

    Object obj = v.remove(1);

    System.out.println(obj + " is removed from Vector");

   

    System.out.println("Vector contents after remove call...");


    for(int index=0; index < v.size(); index++){

       System.out.println(v.get(index));

    }   

    v.removeElementAt(2); 

    System.out.println("Vector contents after removeElementAt call...");
    /* from 
    时   代
展开阅读全文