Java Vector addElement() Method24 Mar 2025 | 2 min read 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:
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:Output: --Elements of Vector are-- Element= A Element= B Element= C ---Elements after addition--- Element= A Element= B Element= C Element= JavaTpoint Example 2:Output: Elements of Vector are: [101, -201, 301] Elements of vector after addition: [101, -201, 301, -5001] Next TopicJava Vector |
Java Method The setElementAt() method of Java Vector class is used to replace the component at the specified index of this vector to be the specified object. Syntax Following is the declaration of setElementAt() method: public void setElementAt(E obj, int index) Parameter Parameter Description Required/Optional index It is the specified index where an element...
2 min read
Java Method The get() method of Java Vector class is used to get the element at the specified position in the vector. Syntax Following is the declaration of get() method: public E get(int index) Parameter DataType Parameter Description Required/Optional int index It is an index of the element which will be returned. Required Return The get() method returns the...
2 min read
Java Method The size() method of Java Vector class is used to get the number of components presents in the vector. Syntax Following is the declaration of size() method: public int size() Parameter This method does not accept any parameter. Return The size() method returns the number of components presents in a...
2 min read
Java Method The toArray() Java Vector class method is used to get an array containing all of the elements in this vector in the correct order. There is two different types of Java toArray() method which can be differentiated depending on its parameter. These are: Java...
3 min read
Java Method The contains() method of Java Vector class is used to check the vector which is in use contains the specified element or not. It returns true if this vector contains the specified element, otherwise returns false. Syntax: Following is the declaration of contains() method: public boolean...
2 min read
Java Method The removeAllElements() method of Java Vector class is used to remove all elements from the vector and set the size of the vector to zero. Syntax Following is the declaration of removeAllElements() method: Public void removeAllElements() Parameter This method does not accept any parameter. Return This method has return type...
2 min read
Java Method The elementAt() method of Java Vector class is used to get the element at the specified index in the vector. Syntax Following is the declaration of elementAt() method: public E elementAt(int index) Parameter DataType Parameter Description Required/Optional int index It is an index into this vector. Required Return The elementAt() method returns an element at the specified...
2 min read
Java Method The lastIndexOf() Java Vector class method is used to get the index of the last occurrence of the specified element in the vector. There are two different types of Java lastIndexOf() method which can be differentiated depending on its parameter. These are: Java Vector...
3 min read
Java Method The clear() method of Java Vector class is used to remove all of the elements from the vector which is in use. Syntax: Following is the declaration of clear() method: Public void clear() Parameter: This method does not accept any parameter. Returns: This method has return type void so, it...
2 min read
Java Method The elements() method of Java Vector class used to get an enumeration of the elements of the vector which is in use. The returned enumeration object will generate all items in this vector at the same location. Syntax: Following is the declaration of elements() method: public...
2 min read
We request you to subscribe our newsletter for upcoming updates.
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India