by BehindJava
WAP to check sorting order in list in Java
In this tutorial, we are going to learn how elements in a list are sorted.
Firstly, a string array has been declared and converted as list. Using sort method, the elements are sorted numerically in ascending order followed by chronology of alphabets.
Sample Code Snippet:
public class SortingCheck {
public static void main(String[] args) {
String[] array= {"abc","9","0","1","bca"};
//converting list to string
List<String> la=Arrays.asList(array);
Collections.sort(la); System.out.println(la);
}
}
Output:
[0, 1, 9, abc, bca]