Vector类在中间插入字符串

来源:互联网 发布:线切割锥度怎样编程 编辑:程序博客网 时间:2024/06/08 17:36
package test;


import java.util.Scanner;
import java.util.Vector;


public class VectorTest {


public static void main(String[] args) {
// TODO Auto-generated method stub
    Vector vct=new Vector();
    Scanner reader=new Scanner(System.in);
    System.out.println("请输入字符串以输入end作为结束");
    String str;
    do{
    str=reader.next();
    vct.addElement(str);
} while (!str.equals("end"));
    System.out.println("显示您输入的所有字符串:");
    System.out.println(vct.toString());
    vct.insertElementAt("NICE", vct.capacity()/2);
    System.out.println("显示插入NICE后的字符串");
    System.out.println(vct.toString());
}
}
原创粉丝点击