As per the documentation: This implementation dumps the specified list into an array, sorts the array, and iterates over the list resetting each element from the corresponding position in the array
Given the program below, I am not able to understand the sorting as how internally jvm judges that letter 'A'
is smaller or bigger than letter 'a'
? As this is a string, the letters won't be assumed in ascii value so how the sorting happens?
public class LetterASort {
public static void main(String[] args) {
ArrayList<String> strings = new ArrayList();
strings.add("aAaA");
strings.add("AaA");
strings.add("aAa");
strings.add("AAaa");
Collections.sort(strings);
for (String s : strings)
{
System.out.print(s + " "); //prints AAaa AaA aAa aAaA
}
}
}
Also I tried debugging the code which created a new doubt for me: the length of array turned out to be 4 rather than 3 as collections.sort
is included in the length