java.util.Vector.size() 方法
描述
size() 方法用于返回此向量中的分量数。
声明
以下是 java.util.Vector.size() 方法的声明
public int size()
参数
NA
返回值
方法调用返回此向量中的分量数。
异常
NA
示例
下面的例子展示了 java.util.Vector.size() 方法的使用。
package com.tutorialspoint;
import java.util.Vector;
public class VectorDemo {
public static void main(String[] args) {
// create an empty Vector vec with an initial capacity of 4
Vector<Integer> vec = new Vector<Integer>(4);
// use add() method to add elements in the vector
vec.add(4);
vec.add(3);
vec.add(2);
vec.add(1);
// let us print the size of the vector
System.out.println("Size of the vector: "+vec.size());
}
}
让我们编译并运行上面的程序,这将产生以下结果.
Size of the vector: 4

