Java Vector trimToSize() Method24 Mar 2025 | 2 min read 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. SyntaxFollowing is the declaration of trimToSize() method: ParameterThis method does not accept any parameter. ReturnThe trimToSize() method does not return anything. It trims the capacity of the given vector with the current size. ExceptionsNA Compatibility VersionJava 1.2 and above Example 1Output: The elements of a vector are: Number = 1 Number = 2 Number = 3 Number = 4 Number = 5 Example 2Output: The initial size of the vector: 9 The elements of a vector are: White Green Black Pink Size of the vector after trimToSize(): 4 Next TopicJava Vector |
Java Method The subList() method of Java Vector class is used to get a view of the portion of the list between fromIndex, inclusive, and toIndex, exclusive. If fromIndex and toIndex are equal, the returned List is empty. Syntax Following is the declaration of subList() method: Public List<E>...
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 iterator() method of Java Vector class is used to get an iterator over the elements in this list in proper sequence. Syntax Following is the declaration of an iterator() method: Public Iterator<E> iterator() Parameter This method does not accept any parameter. Return The iterator() method returns an iterator over...
2 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 indexOf() Java Vector class method is used to get the index of the first occurrence of the specified element in the vector. There are two different types of Java indexOf() method which can be differentiated depending on its parameter. These are: Java Vector...
3 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 insertElementAt() method of Java Vector class is used to insert the specified object as a component in this vector at the specified index. Each component in the vector with an index greater or equal to the given index is shifted upward. Now,...
3 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 remove() Java Vector class method is used to remove the specified element from the vector. There are two different types of Java remove() method which can be differentiated depending on its parameter. These are: Java Vector remove(int index) Method Java Vector remove(Object o) Method remove(int...
3 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
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