sort(Comparator): This method is available in java.util.Vector class of Java.
Syntax:
void java.util.Vector.sort(Comparator<? super K> c)
This method takes one argument. This method sorts this list according to the order induced by the specified Comparator.
Note: The sort is stable: this method must not reorder equal elements.
Parameters: One parameter is required for this method.
c: the Comparator used to compare list elements. A null value indicates that the elements' natural ordering should be used.
Returns: NA
Exceptions: NA
Approach
Java
import java.util.Vector;public class Vectorsort {public static void main(String[] args) {Vector<String> vector = new Vector<>();vector.add("Hello");vector.add("Java");vector.add("C++");vector.add("Program");vector.sort(null);System.out.println(vector);}}
Output:
[C++, Hello, Java, Program]
No comments:
Post a Comment