I'm trying to do some exercise on Streams and encountered following problem:
I have a text file, and I want to compute the average number of words per line. Can someone tell me if my way of thinking is correct? Here's some pseudocode I think should do the trick once implemented:
double wordCount(String filepath){
return Files.lines(Paths.get(filepath))
// make a wordarray of the line
// average the size of every wordarray with something like that
(collect(Collectors.averagingDouble())
Can someone please help me with that?
How can I convert a line to a String array of words?
How do I get the size of that array?