I have an ArrayList<String>
containing a list of 'Building Key' numbers.
Forgive me if this has been answered before I am struggling to find a solution by searching.
public class SortKeyNumbers {
public static void main(String args[]) {
ArrayList<String> keys = new ArrayList<>();
keys.add("1");
keys.add("10");
keys.add("2");
keys.add("3");
keys.add("3B");
keys.add("12");
keys.add("12C");
keys.add("21");
keys.add("32");
Collections.sort(keys);
System.out.println(keys);
}
}
This gives me an output of [1, 10, 12, 12C, 2, 21, 3, 32,3B]
I know that this is as expected from Collections.sort
What I need is an output of [1, 2, 3, 3B, 10, 12, 12C, 21, 32]
What I am asking is help to write the correct comparator
or compareTo
to achieve the desired output.