I'm considering how to sort an ArrayList with two parameters. First by occurences of some char in string, then by natural order. Here is the code:
ArrayList<String> words;
words=getWords(sentence);//return all words from sentence
words.sort(Comparator.comparing(o -> countChar(c, o))
.thenComparing(Comparator::naturalOrder));
Method getWords(sentence)
return an ArrayList<String>
of words from sentence
.
Method countChar(c,o)
counts number of char c
in word o
.
When adding .thenComparing(Comparator::naturalOrder))
IDE shows that o
should be cast to String
and that it can't resolve method thenComparing()
.
What might be the problem?