Home » Core Java » util » Vector (page 2)

Vector

Vector Iterator example

In this example we shall show you how to obtain a Vector Iterator, in order to iterate through a Vector’s elements. To obtain a Vector Iterator one should perform the following steps: Create a new Vector. Populate the vector with elements, with add(E e) API method of Vector. Invoke iterator() API method of Vector, to get the Iterator. Iterate through ...

Read More »

Insert all elements of Collection to specific Vector index

With this example we are going to demonstrate how to insert all elements of a Collection to specific Vector index, using the ArrayList as a Collection implementation. In short, to insert all elements of an ArrayList to a specific Vector index you should: Create a new Vector. Populate the vector with elements, with add(E e) API method of Vector. Create ...

Read More »

Get sub list of Vector example

This is an example of how to get the sub list of a Vector. The Vector API provides the subList(int fromIndex, int toIndex) method. Getting a Vector sub list implies that you should: Create a new Vector. Populate the vector with elements, with add(E e) API method of Vector. Invoke subList(int fromIndex, int toIndex) method of Vector. The method returns ...

Read More »

Vector size example

In this example we shall show you how to get the Vector size, that is the number of elements that a Vector contains. To get the Vector size one should perform the following steps: Create a new Vector. Populate the vector with elements, with add(E e) API method of Vector. Get the Vector size, using size() API method of Vector. ...

Read More »

Convert Vector to Object array example

With this example we are going to demonstrate how to convert a Vector to an Object array. In order to convert a Vector to Object array we need to fill the array with all the elements in the vector in the correct order. In short, to convert a Vector to an object array you should: Create a new Vector. Populate ...

Read More »

Append all elements of a Collection to Vector example

This is an example of how to append all elements of a Collection to a Vector. We are using an ArrayList as a Collection implementation. Appending all elements of an ArrayList to a Vector implies that you should: Create a new Vector. Populate the vector with elements, with add(E e) API method of Vector. Create a new ArrayList. Populate the ...

Read More »

Add element to specified index of Vector example

In this example we shall show you how to add an element to a specified index of a Vector. The Vector API provides both add(E e) and add(int index, E element) methods, to add an element either at the end of the Vector or at a specified index of a Vector. To add an element to a specified index of ...

Read More »