101
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.
Syntax
Following is the declaration of a sort() method:
Parameter
Parameter | Description | Required/Optional |
---|---|---|
c | It is the Comparator which is used to compare vector elements. | Required |
Return
This method has return type void so, it does not return anything.
Exceptions
NA
Compatibility Version
Java 1.2 and above
Example 1
Output:
Components of the vector: [1, 5, 2, 4, 3] Components of the vector after sorting: [1, 2, 3, 4, 5]
Example 2
Output:
The vector elements are: White Green Black Orange The vector elements after sort() method are: Black Green Orange White
Next TopicJava Vector