1.视频链接:13.13 Vector使用_哔哩哔哩_bilibilihttps://www.bilibili.com/video/BV1zD4y1Q7Fw/?p=13&spm_id_from=333.1007.top_right_bar_window_history.content.click&vd_source=b5775c3a4ea16a5306db9c7c1c1486b52.代码示例:
package com.yundait.Demo01;import java.util.Enumeration;
import java.util.Vector;public class VectorDemo01 {public static void main(String[] args) {//创建集合Vector vector = new Vector<>();//1.添加元素vector.add("草莓");vector.add("芒果");vector.add("西瓜");System.out.println("元素个数"+ vector.size());//2删除元素//vector.remove(0);//vector.remove("西瓜");//vector.clear();System.out.println("删除后元素个数" + vector.size());System.out.println(vector.toString());//3.遍历//使用枚举器Enumeration elements = vector.elements();while (elements.hasMoreElements()){String o = (String)elements.nextElement();System.out.println(o);}//4.判断System.out.println(vector.contains("西瓜"));System.out.println(vector.isEmpty());//5.Vector其他方法System.out.println("-----------------------");System.out.println(vector.toString());System.out.println(vector.firstElement());System.out.println(vector.lastElement());System.out.println(vector.elementAt(1));}
}