- 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
Advertisements