This class implements an ordered collectionessentially an arrayof objects that can grow or shrink as necessary. In Java 1.2, Vector has been modified to implement the List interface. Unless the synchronized methods of the Vector class are actually needed, ArrayList is preferred in Java 1.2 and later. In Java 5.0 this class has been made generic. The type variable E represents the type of the elements of the vector. Vector is useful when you need to keep track of a number of objects, but do not know in advance how many there will be. Use setElementAt( ) to set the object at a given index of a Vector . Use elementAt( ) to retrieve the object stored at a specified index. Call add( ) to append an object to the end of the Vector or to insert an object at any specified position. Use removeElementAt( ) to delete the element at a specified index or removeElement( ) to remove a specified object from the vector. size ( ) returns the number of objects currently in the Vector . elements( ) returns an Enumeration that allows you to iterate through those objects. capacity( ) is not the same as size( ) ; it returns the maximum number of objects a Vector can hold before its internal storage must be resized. Vector automatically resizes its internal storage for you, but if you know in advance how many objects a Vector will contain, you can increase its efficiency by pre-allocating this many elements with ensureCapacity( ) . Figure 16-68. java.util.Vector<E>public class Vector<E> extends AbstractList<E> implements List<E>, RandomAccess, Cloneable, Serializable { // Public Constructors public Vector ( ); 1.2 public Vector (Collection<? extends E> c ); public Vector (int initialCapacity ); public Vector (int initialCapacity , int capacityIncrement ); // Public Instance Methods public void addElement (E obj ); synchronized public int capacity ( ); synchronized public boolean contains (Object elem ); Implements: List public void copyInto (Object[ ] anArray ); synchronized public E elementAt (int index ); synchronized public Enumeration<E> elements ( ); public void ensureCapacity (int minCapacity ); synchronized public E firstElement ( ); synchronized public int indexOf (Object elem ); Implements: List public int indexOf (Object elem , int index ); synchronized public void insertElementAt (E obj , int index ); synchronized public boolean isEmpty ( ); Implements: List synchronized default:true public E lastElement ( ); synchronized public int lastIndexOf (Object elem ); Implements: List synchronized public int lastIndexOf (Object elem , int index ); synchronized public void removeAllElements ( ); synchronized public boolean removeElement (Object obj ); synchronized public void removeElementAt (int index ); synchronized public void setElementAt (E obj , int index ); synchronized public void setSize (int newSize ); synchronized public int size ( ); Implements: List synchronized public void trimToSize ( ); synchronized // Methods Implementing List 1.2 public boolean add (E o ); synchronized 1.2 public void add (int index , E element ); 1.2 public boolean addAll (Collection<? extends E> c ); synchronized 1.2 public boolean addAll (int index , Collection<? extends E> c ); synchronized 1.2 public void clear ( ); public boolean contains (Object elem ); 1.2 public boolean containsAll (Collection<?> c ); synchronized 1.2 public boolean equals (Object o ); synchronized 1.2 public E get (int index ); synchronized 1.2 public int hashCode ( ); synchronized public int indexOf (Object elem ); public boolean isEmpty ( ); synchronized default:true public int lastIndexOf (Object elem ); synchronized 1.2 public boolean remove (Object o ); 1.2 public E remove (int index ); synchronized 1.2 public boolean removeAll (Collection<?> c ); synchronized 1.2 public boolean retainAll (Collection<?> c ); synchronized 1.2 public E set (int index , E element ); synchronized public int size ( ); synchronized 1.2 public List<E> subList (int fromIndex , int toIndex ); synchronized 1.2 public Object[ ] toArray ( ); synchronized 1.2 public <T> T[ ] toArray (T[ ] a ); synchronized // Protected Methods Overriding AbstractList 1.2 protected void removeRange (int fromIndex , int toIndex ); synchronized // Public Methods Overriding AbstractCollection public String toString ( ); synchronized // Public Methods Overriding Object public Object clone ( ); synchronized // Protected Instance Fields protected int capacityIncrement ; protected int elementCount ; protected Object[ ] elementData ; } SubclassesStack |