E
E
evgenyt20002021-01-27 02:56:11
Java
evgenyt2000, 2021-01-27 02:56:11

Why doesn't StreamApi sorting work?

Good afternoon !
Sorting not working

List<String> expectedOrderedByAscList = actualOrderedByAscList
                .stream()
                .sorted(Comparator.naturalOrder())
                .collect(Collectors.toList());


This option is not correct because there is a problem with cases like aaa aab Follows
the first letter of the

second
List<String> expectedOrderedByAscList = actualOrderedByAscList
                    .stream()
                    .sorted((String s1,String s2)->{ return s1.compareTo(s2);})
                    .collect(Collectors.toList());


It doesn't work.... If anyone can suggest/ tell me
what the problem is, thank you! ie non-alphabetic) results. It will sort any uppercase letter before all lowercase letters, so the array ["aAAA","Zzz", "zzz"] sorts before ["Zzz", "aAAA", "zzz"]

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question