Java Vector trimToSize() Example

The trimToSize() method of java.util.Vector class trims the capacity of the vector to be the vector’s current size. If the capacity of the vector is larger than its current size, then the capacity is changed to equal the size by replacing its internal data array, kept in the field elementData with a smaller one.

[Read more…]

Java Vector set(int index, E element) Method Example

We have already seen add(int index, E element) method of java.util.Vector class which will insert the specified element at the specified position in the Vector and shifts the element currently at that position to the right and the new element will added at that index. whereas set(int index, E element) method will replace the element at the specified position in the Vector with the specified element.

[Read more…]

Java Vector removeRange(int fromIndex,int toIndex) Method Example

The remove(int index)  and removeElementAt(int index) method of java.util.Vector class removes the element at the specified index. Each component in this vector with an index greater or equal to the specified index is shifted downward to have an index one smaller than the value it had previously whereas removeRange(int fromIndex,int toIndex) method removes from the vector all of the elements whose index is between fromIndex inclusive and toIndex exclusive
[Read more…]