Home Java SCJP SCWCD Servlet Submit News Contact Us Site Map


Over 500 magazines for free (including Oracle Magazine)!

Yes all of them are FREE. You can subscribe to ALL of them.
Click here to apply today!

Home > Java > Java Articles

 Getting elements from the Vector

1) Object get(int index)

Returns the element at the specified index in the Vector.

Note : We need to downcast the returned object to the desired type.


2) Object firstElement()

Returns the first element of the Vector (i.e. at index 0)

3) Object lastElement()

Returns the last element of the Vector (i.e. at index size - 1)


Removing elements from the Vector

1) Object remove(int index)

Removes the elements at the specified index in the Vector and shifts the subsequent element of the list by one. This method returns the element that has been removed from the Vector. This method can throw IndexOutOfBoundException if the index specified is out of range.

2) void removeElementAt (int index)

Removes the elements at the specified index in the Vector and shifts the subsequent element of the list by one. This method can throw ArrayIndexOutOfBoundException if the index specified is out of range.

3) boolean remove (Object object)

Removes the first occurrence of the specified Object from the Vector if found. Returns true if the object is remove from the Vector, otherwise returns false.

4) boolean removeElement (Object object)

Removes the first occurrence of the specified Object from the Vector if found. Returns true if the object is remove from the Vector, otherwise returns false.

5) boolean remove (Collection collection)

Remove all elements of the Vector which are found in the Collection specified. Returns true if the Vector is changed, otherwise returns false. This method can throw NullPointerException if the specified Collection is null.


6) void removeRange(int startIndex, int endIndex)

Removes the elements from Vector whose index is between startIndex inclusive and endIndex exclusive and shifts the subsequent elements of the Vector.


7) void clear()

Removes all elements of the Vector.

8) void removeAllElements()

Removes all elements of the Vector.


Convert Vector in to an Object array

1) Object[] toarray()

Returns array of Object containing all elements of the Vector in the correct order.


<< Java Add Replace Elements

Java Vector Example >>

Home Java SCJP SCWCD Servlet Site map