Java Vector sort() Method
The sort() method of Java Vector class is used to sort the vector according to the order induced by the specified Comparator.
Following is the declaration of a sort() method:
This method has return type void so, it does not return anything.
Java 1.2 and above
Example 1Test it Now
Components of the vector: [1, 5, 2, 4, 3] Components of the vector after sorting: [1, 2, 3, 4, 5]
Example 2Test it Now
The vector elements are: White Green Black Orange The vector elements after sort() method are: Black Green Orange White