I have a list with some strings in this format:
List<String> ids = new ArrayList<>();
ids.add("B-7");
ids.add("B-5");
ids.add("A-3");
ids.add("B-8");
ids.add("B-1");
ids.add("B-6");
ids.add("B-2");
ids.add("B-3");
ids.add("B-10");
ids.add("A-1");
ids.add("B-4");
ids.add("B-9");
ids.add("A-2");
I need to sort it to have this output, (iterating over the list):
A-1
A-2
A-3
B-1
B-2
B-3
B-4
B-5
B-6
B-7
B-8
B-9
B-10
I am using:
List<String> sortedIds = ids.stream().sorted().collect(Collectors.toList());
But instead, my output:
A-1
A-2
A-3
B-1
B-10 -- Error
B-2
B-3
B-4
B-5
B-6
B-7
B-8
B-9