清空向量的元素
您可以使用clear()方法删除给定向量中的所有元素。
示例
import java.util.Vector; public class ClearingElements { public static void main(String args[]) { Vector vect = new Vector(); vect.addElement("Java"); vect.addElement("JavaFX"); vect.addElement("HBase"); vect.addElement("Neo4j"); vect.addElement("Apache Flume"); System.out.println("Elements of the vector :"+vect); vect.clear(); System.out.println("Elements of the vector after clearing it :"+vect); } }
输出
Elements of the vector :[Java, JavaFX, HBase, Neo4j, Apache Flume] Elements of the vector after clearing it :[]
广告