Thursday 5 April 2012

Class - Vector


Vector

  Vector implements a dynamic array vector is synchronized, and it contains many legacy methods that are not part of the collection framework.
 constructors

     Vector()
     Vector(int size)
     Vector(int size,int incr)
     Vector(collection c)
 
The first form is the default vector constructors. It initial size of 10.

The second form creates a vector whose initial capacity is specified by size.

The third form creates a vector whose initial capacity is specified by size and increment is specified by incr.

The fourth form creates a vector that contains the elements of collection c.

Vector defines these protected data members:
           
            int capacityIncrement;
            int elementCount;
            Object elementData[];
 
The increment value is stored in capacity Increment. The number of elements currently in the vector is stored in elementCount. The array that holds the vector is stored in elementData.

Method

final void addElement(object element)
The object specified by element is added to the vector.

final Enumeration elements()
Returns an enumeration of the elements in the vector.
 
final object firstElement()
            Returns the first element in the vector.
 
final object lastElement()
            Returns the last element in the vector.
 
final void removeElementAt(int index)
Removes the element at the location specified by index.
 
final void setSize(int size)
Sets the number of elements in the vector to size. If the new size is less than the old size, elements are lost. If the new size is larger than the old size, null elements are added.

final int Size()
            Returns the number of elements currently in the vector.

Posted By : Ruchita Pandya

No comments:

Post a Comment