Javatpoint Logo
Javatpoint Logo

Java Vector addElement() Method

The addElement() method of Java Vector class is used to add the specified element to the end of this vector. Adding an element increases the vector size by one.

Syntax:

Following is the declaration of addElement() method:

Parameter:

Parameter Description Required/Optional
e It is the element which will be added to the vector. Required

Returns:

The addElement() method does not return anything because its return type is void.

Exceptions:

NA

Compatibility Version:

Java 1.2 and above

Example 1:

Test it Now

Output:

--Elements of Vector are--
Element= A
Element= B
Element= C
---Elements after addition--- 
Element= A
Element= B
Element= C
Element= JavaTpoint

Example 2:

Test it Now

Output:

Elements of Vector are: [101, -201, 301]
Elements of vector after addition: [101, -201, 301, -5001]

Next TopicJava Vector





Youtube For Videos Join Our Youtube Channel: Join Now

Feedback

  • Send your Feedback to feedback@javatpoint.com

Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA