Java Vector Methods

Java Vector Methods

Four programs are given on Vector to know thoroughly about Vector and above methods. Vector is a general purpose data structure user very often by the programmer even though the collections come with many classes.

  1. Vector – Methods: Uses all the methods of Vector class like capacity, size, firstElement etc.
  2. Vector – Generics: Create generics vector storing only integers and uses all Collections static methods like swap, shuttle, fill, rotate etc.
  3. Vector – Retrieval: Illustrates some more methods like get, remove, removeAll and also how to retrieve the elements – 6 styles
  4. Vector – Play With: Give manipulations on vector elements like removing duplicate values, converting vector elements into an array etc.

In the following program many of the above methods of Vector are used.

Java Vector Methods
Output screen of of Java Vector Methods

All the methods used in the code are explained earlier under "Vector Methods".

More methods like get, remove(), removeAll() and setElementAt() are discussed in the second program of vector – Vector Retrieval.

3 thoughts on “Java Vector Methods

  1. Mann Chauhan

    Hello sir, I think there is a mistake: the second vector object vect2 is created with a default capacity of 50. When 50 used out, it adds 50 more not 10!!!
    and when 100 used out, it adds 100 more and then capacity becomes 200. i tried this.

Leave a Reply

Your email address will not be published. Required fields are marked *