Vector可以在Java中包含异构对象吗?
由于向量以对象的形式存储元素,因此您可以在其中存储各种类型(异构)的对象。
例:
import java.util.*;class Demo{}public class VectorSample { public static void main(String args[]) { Demo obj = new Demo(); Vector v = new Vector(3, 2); System.out.println("Initial size: " + v.size()); System.out.println("Initial capacity: " + v.capacity()); v.addElement(new Integer(1)); v.addElement(new String("krishna")); v.addElement(new Float(3.5f)); v.addElement(obj); System.out.println("Capacity after four additions: " + v.capacity()); }}