I am trying to read a text file and get a stream of the words inside it. By words, I mean simply Strings that are space delimited. I know Java has Files.lines() method that gives a Stream<String> but this is a stream of lines. I wish to post-process this stream by splitting each line with space. But the following code:
return Files.lines(Path.of(filename)).map((line)-> line.split(" "));
gives me a compilation error:
Type mismatch: cannot convert from Stream<Object> to Stream<String>Java(16777235)
Is there some casting that I need to do here to Stream<String> or is there a better way to get a stream of words?