Java Vector clear() Method24 Mar 2025 | 1 min read 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: Parameter:This method does not accept any parameter. Returns:This method has return type void so, it does not return any value. Exceptions:NA Compatibility Version:Java 1.2 and above Example 1:Output: Size of Vector before clear() method: 3 Size of Vector after clear() method: 0 Example 2:Output: Elements of Vector is: [3, 5, 2, 4, 1] Elements of Vector after clear(): [] Next TopicJava Vector |
Java Method The removeRange() method of Java Vector class is used to delete all elements from the vector whose index is between fromIndex, inclusive and toIndex, exclusive. The removal of elements shifts any succeeding elements to the left (reduces their index). Syntax Following is the declaration of...
2 min read
Java Method The clone() method of Java Vector class is used to get a clone of the vector which is in use. Syntax: Following is the declaration of clone() method: Public object clone() Parameter: This method does not accept any parameter. Returns: This method returns a clone of the vector which is...
2 min read
Java Method The removeElementAt() method of Java Vector class is used to delete the component at the specified index. Each element in this vector with an index greater or equal to the given index is shifted downward. Now the vector index is one smaller than...
2 min read
Java Method The spliterator() method of Java Vector class is used to create a late-binding and fail-fast spliterator over the elements in this list. Syntax Following is the declaration of spliterator() method: public Spliterator<E> spliterator() Parameter This method does not accept any parameter. Return The spliterator() method returns a spliterator over the...
2 min read
Java Method The retainAll() method of Java Vector class is used to retain only that elements in the vector which are contained in the specified collection. In other words, it removes all elements from this vector that are not contained in the specified collection. Syntax Following is...
3 min read
Java Method The capacity() method of Java Vector class is used to get the current capacity of the vector which is in use. Syntax: Following is the declaration of capacity() method: Public int capacity() Parameter: This method does not accept any parameter. Returns: This method returns the current capacity of the vector...
2 min read
Java Method The firstElement() method of Java Vector class is used to get the first element ( at index 0 ) of the vector which is in use. Syntax: Following is the declaration of firstElement() method: public E firstElement() Parameter: This method does not accept any parameter. Returns: The firstElement() method returns...
2 min read
Java 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: Public void addElement(E e) Parameter: Parameter Description Required/Optional e It is the element which will...
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
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
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