- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Add elements at the end of a Vector in Java
Elements can be added at the end of a Vector using the java.util.Vector.add() method. This method has a single parameter i.e. the element to be added. It returns true if the element is added to the Vector as required and false otherwise.
A program that demonstrates this is given as follows:
Example
import java.util.Vector; public class Demo { public static void main(String args[]) { Vector vec = new Vector(5); for (int i = 1; i <= 10; i++) { vec.add(i); } System.out.println("The Vector elements are: " + vec); } }
Output
The Vector elements are: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
Now let us understand the above program.
The Vector is created. Then Vector.add() is used to add the elements to the Vector using a for loop. Finally, the Vector elements are displayed. A code snippet which demonstrates this is as follows:
Vector vec = new Vector(5); for (int i = 1; i <= 10; i++) { vec.add(i); } System.out.println("The Vector elements are: " + vec);
- Related Articles
- Add elements at the middle of a Vector in Java
- Add elements at beginning and end of LinkedList in Java
- Add elements to a Vector in Java
- How to create a string vector with numbers at the end in R?
- Replace all the elements of a Vector with Collections.fill() in Java
- Clear out all of the Vector elements in Java
- Enumerate through the Vector elements in Java
- Removing Single Elements in a Vector in Java
- How to add comma at the end of cell/text in Excel?
- Loop through the Vector elements using a ListIterator in Java
- Golang Program to add a node at the end of a given linked list.
- Replace an element at a specified index of the Vector in Java
- How to remove dot and number at the end of the string in an R vector?
- How to add elements to AbstractSequentialList class at a specific position in Java?
- Append all elements of another Collection to a Vector in Java

Advertisements