Vector类在中间插入字符串

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

你可能感兴趣的:(java)