Java Vector addElement() method example

In this source code example, we will demonstrate the usage of the Vector addElement() method in Java with an example.

Vector Java.util.Vector.addElement() Method

Java.util.Vector.addElement(): This method is used to append a specified element to the end of this vector by increasing the size of the vector by 1. The functionality of this method is similar to that of the add() method of the Vector class.

Java.util.Vector.addElement() Method Example

Below program illustrates the working of Java.util.Vector.addElement() method:

// Java code to illustrate boolean add(Object element) 
import java.util.*; 
public class VectorDemo { 
    public static void main(String args[]) 
        // Creating an empty Vector 
        Vector programLangs = new Vector(); 
        // Use add() method to add elements in the vector 
        // Output the present vector 
        System.out.println("The vector is: " + programLangs); 
            * Adds the specified component to the end of this vector, increasing
            * its size by one. The capacity of this vector is increased if its size
            * becomes greater than its capacity.
        // Printing the new vector 
        System.out.println("The new Vector is: " + programLangs); 


The vector is: [C, C++, Java, Python, Go]
The new Vector is: [C, C++, Java, Python, Go, Scala, JavaScript]         


Free Spring Boot Tutorial - 5 Hours Full Course

Watch this course on YouTube at Spring Boot Tutorial | Fee 5 Hours Full Course