- 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
What does the method addElement(E obj) do in java?
The addElement(E obj) method is used to add the specified component to the end of this vector and increasing its size by one. The capacity of this vector is increased if its size becomes greater than its capacity. This addElement() method is identical in functionality to the add(Object) method. The add() method returns true/false but the addElement() method does not return any value.
Example
import java.util.Vector; public class VectorDemo { public static void main(String[] args) { Vector<Integer> vec = new Vector<Integer>(4); vec.add(4); vec.add(3); vec.add(2); vec.add(1); System.out.println("Initial elements in the vector :- "); for (Integer number : vec) { System.out.println("Number = " + number); } vec.addElement(12); System.out.println("Elements after addition :- "); for (Integer number : vec) { System.out.println("Number = " + number); } } }
Output
Initial elements in the vector :- Number = 4 Number = 3 Number = 2 Number = 1 Elements after addition :- Number = 4 Number = 3 Number = 2 Number = 1 Number = 12
- Related Articles
- What does the method equals(obj[] a1, obj[] a2) do in java?
- What does the method remove(obj o) do in java?
- What does the method hashCode(obj[] a) do in java?
- What does the method sort(obj[] a) do in java?
- What does the method toString(obj[] a) do in java?
- What does the method contains(obj o) do in java?
- What does the method indexOf(obj o) do in java?
- What does the method lastIndexOf(obj o) do in java?
- What does the method set(int, obj o) do in java?
- What does the method addFirst(E e) do in java?
- What does the method addLast(E e) do in java?
- What does the method fill(obj[], object val) do?
- What does the method sort(obj[] a, int fromIndex, int toIndex) do in java?
- What does the method fill(obj[], int fromIndex, int toIndex, int val) do in java?
- What does the method add(E element) do in java?

Advertisements