Last Updated : 11 Jul, 2025
The Java.util.Vector.addElement() 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 Vector class.
Syntax:
boolean addElement(Object element)
Below programs illustrate the working of java.util.Vector.add(Object element) method.
Example 1 :
Java
// Java Program to illustrate
// boolean addElement()
import java.util.*;
public class GFG
{
public static void main(String args[])
{
// Creating an empty Vector
Vector<String> v = new Vector<String>();
// Add elements in the vector
v.add("Geeks");
v.add("for");
v.add("Geeks");
// Output the present vector
System.out.println("The vector is : " + v);
// Adding new elements to the end
v.addElement("Last");
v.addElement("Element");
// Printing the new vector
System.out.println("The new Vector is : " + v);
}
}
The vector is : [Geeks, for, Geeks] The new Vector is : [Geeks, for, Geeks, Last, Element]
Example 2:
Java
// Java Program to illustrate
// boolean addElement()
import java.util.*;
public class VectorDemo
{
public static void main(String args[])
{
// Creating an empty Vector
Vector<Integer> v = new Vector<Integer>();
// Add elements in the vector
v.add(1);
v.add(2);
v.add(3);
// Output the present vector
System.out.println("The vector is : " + v);
// Adding new elements to the end
v.addElement(50);
v.addElement(100);
// Printing the new vector
System.out.println("The new vector is : " + v);
}
}
The vector is : [1, 2, 3] The new vector is : [1, 2, 3, 50, 100]
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4