Java Vector sort() Method24 Mar 2025 | 2 min read The sort() method of Java Vector class is used to sort the vector according to the order induced by the specified Comparator. SyntaxFollowing is the declaration of a sort() method: Parameter
ReturnThis method has return type void so, it does not return anything. ExceptionsNA Compatibility VersionJava 1.2 and above Example 1Output: Components of the vector: [1, 5, 2, 4, 3] Components of the vector after sorting: [1, 2, 3, 4, 5] Example 2Output: The vector elements are: White Green Black Orange The vector elements after sort() method are: Black Green Orange White Next TopicJava Vector |
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 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 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 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 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 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 addAll() Java Vector class method inserts all of the elements in the specified collection to the end of the vector which is in use. The order of the elements will be the same as they are returned by the specified collection's iterator....
5 min read
Java Method The containsAll() method of Java Vector class is used to check the vector which is in use contains all of the elements in the specified Collection or not. It returns true if this vector contains all of the elements in the Collection, otherwise...
3 min read
Java Method The forEach() method of Java Vector class is used to perform the given action for each element of the Iterable until all elements have been processed or the action throws an exception. Actions are performed in the order of iteration if that order...
2 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
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