Read one line of text and summarise its words using streams and collectors.
A word is a maximal run of letters A–Z/a–z; everything else separates words. Convert every word to lower case before processing. The line may be empty or contain no letters at all.
Print exactly four lines:
Words:and the number of words;Distinct:and the distinct words in alphabetical order, as[w1, w2, …]([]when there are none);Longest:and the longest word — if several share the maximum length, the alphabetically first — ornone;By length:and a map from word length to number of words, keys in increasing order, printed with the map'stoString(e.g.{3=5, 5=1}, or{}).
Input:
The cat saw the other cat.
Output:
Words: 6
Distinct: [cat, other, saw, the]
Longest: other
By length: {3=5, 5=1}
Hint: line.split("[^A-Za-z]+") can produce an empty first element, so filter it out.