Java Vector removeAllElements() Method24 Mar 2025 | 1 min read 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. SyntaxFollowing is the declaration of removeAllElements() method: ParameterThis method does not accept any parameter. ReturnThis method has return type void so, it does not return anything. ExceptionsNA Compatibility VersionJava 1.2 and above Example 1Output: Size of Vector before removeAllElements() method: 3 Size of Vector after removeAllElements() method: 0 Example 2Output: Elements of Vector is: [3, 5, 2, 4, 1] Elements of Vector after removeAllElements(): [] Size of Vector after removeAllElements() method: 0 Next TopicJava Vector |
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 removeAll() method of Java Vector class deletes all the elements from the vector that are present in the specified collection. Syntax Following is the declaration of removeAll() method: public boolean removeAll(Collection<?> c) Parameter Parameter Description Required/Optional c It is a collection of elements which will be removed from the vector. Required Return The removeAll()...
3 min read
Java Method The setSize() method of Java Vector class is used to set the size of a vector. If the new size is greater than the current size, null items are added to the end of the vector. Otherwise, all components at index newSize and...
3 min read
Java Method The toString() method of Java Vector class is used to get a string representation of the vector. It contains the string representation of each element. Syntax Following is the declaration of toString() method: public String toString() Parameter This method does not accept any parameter. Return The toString() method returns a...
2 min read
Java Method The ensureCapacity() method of Java Vector class is used to increase the capacity of the vector which is in use, if necessary. It ensures that the vector can hold at least the number of components specified by the minimum capacity argument. Syntax: Following is 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 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 equals() method of Java Vector class used to compare the specified object with this Vector for equality. It returns true if and only if the specified object is also a list, both lists have the same size and all corresponding pairs of...
2 min read
Java Method The trimToSize() method of Java Vector class is used to trim the capacity of the vector to be the vector's current size. An application can use this operation to minimize the storage of a vector. Syntax Following is the declaration of trimToSize() method: public void trimToSize() Parameter This...
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
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