Home » Core Java » util » Vector

Vector

Vector Enumeration example

This is an example of how to obtain a Vector Enumeration in Java. Obtaining a Vector Enumeration implies that you should: Create a new Vector. Populate the vector with elements, with add(E e) API method of Vector. Invoke elements() API method of Vector to get an Enumeration of the Vector’s elements. Enumerate through the elements of an Enumeration, with hasMoreElements(), ...

Read More »

Sort Vector example using Collections sort

In this example we shall show you how to sort the elements of a Vector, using the Collections API, and in particular the sort(List list) API method. To sort the elements of a Vector one should perform the following steps: Create a new Vector. Populate the vector with elements, with add(E e) API method of Vector. Invoke the sort(List list) ...

Read More »

Set Vector size example

With this example we are going to demonstrate how to set the Vector size, that is setting a greater or less size than the current size of the Vector. In short, to set the Vector size you should: Create a new Vector. Populate the vector with elements, with add(E e) API method of Vector. Invoke the setSize(int newSize) API method ...

Read More »

Search elements in Vector from index example

This is an example of how to search an element in a Vector from its index. Searching elements in a Vector from index implies that you should: Create a new Vector. Populate the vector with elements, with add(E e) API method of Vector. Invoke indexOf(Object o, int index) API method of Vector. The method returns the index of the first ...

Read More »

Search elements in Vector example

In this example we shall show you how to search elements in a Vector. The Vector API provides us with methods for such operations. To search elements in a Vector one should perform the following steps: Create a new Vector. Populate the vector with elements, with add(E e) API method of Vector. Invoke contains(Object o) API method of Vector to ...

Read More »

Replace Vector elements using index example

With this example we are going to demonstrate how to replace Vector elements using index. The Vector API provides methods for such operations. In short, to replace elements in a Vector using index you should: Create a new Vector. Populate the vector with elements, with add(E e) API method of Vector. Invoke set(int index, E element) API method of Vector, ...

Read More »

Remove Vector element example

This is an example of how to remove an element from a Vector. We are using the remove(Object o) API method of Vector. Removing an element from a Vector implies that you should: Create a new Vector. Populate the vector with elements, with add(E e) API method of Vector. Remove an element from the Vector, using remove(Object o) API method. ...

Read More »

Remove Vector elements using index example

In this example we shall show you how to remove elements from a Vector using index. To remove an element from a Vector using index one should perform the following steps: Create a new Vector. Populate the vector with elements, with add(E e) API method of Vector. Remove an element from the Vector. Invoke remove(int index) API method of Vector, ...

Read More »

Remove all elements from Vector example

With this example we are going to demonstrate how to remove all elements from a Vector. We are using clear() API method of Vector. In short, to remove all elements from a Vector you should: Create a new Vector. Populate the vector with elements, with add(E e) API method of Vector. Invoke clear() API method of Vector. The method removes ...

Read More »

Vector ListIterator example

This is an example of how to obtain a Vector ListIterator. Obtaining a ListIterator of a Vector implies that you should: Create a new Vector. Populate the vector with elements, with add(E e) API method of Vector. Invoke listIterator() API method of Vector, to get the ListIterator. Use hasNext() and next() methods of ListIterator for forward iteration over the collection ...

Read More »

Want to take your Java skills to the next level?

Grab our programming books for FREE!

Here are some of the eBooks you will get:

  • Spring Interview QnA
  • Multithreading & Concurrency QnA
  • JPA Minibook
  • JVM Troubleshooting Guide
  • Advanced Java
  • Java Interview QnA
  • Java Design Patterns