Java basics
addElement()
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.
Syntax:public void addElement(E obj)
Example:import java.util.Vector;
public class VectorDemo {
public static void main(String[] args) {
// create an empty Vector vec with an initial capacity of 4
Vector vec = new Vector&;ltInteger>(4);
// use add() method to add elements in the vector
vec.add(4);
vec.add(3);
vec.add(2);
vec.add(1);
// let us print all the elements available in vector
System.out.println("Initial elements in the vector :- ");
for (Integer number : vec) {
System.out.println("Number = " + number);
}
// add new element
vec.addElement(12);
// let us print all the elements again after addition
System.out.println("Elements after addition :- ");
for (Integer number : vec) {
System.out.println("Number = " + number);
}
}
}
Content
License.
All information of this service is derived from the free sources and is provided solely in the form of quotations.
This service provides information and interfaces solely for the familiarization (not ownership) and under the "as is" condition.
Copyright 2016 © ELTASK.COM. All rights reserved.
Site is optimized for mobile devices.
Downloads: 26 / 159170609. Delta: 0.02753 с