I am fairly new to streams, so please help me out (and be gentle).
What I would like to do is the following. I have a BufferedReader
that reads from a file in which each line looks something like this: "a, b". For example:
Example Input file
"a, b"
"d, e"
"f, g"
I would like to convert this to a LinkedList<String[]>
:
Example LinkedList<String[]>
[{"a", "b"}, {"c", "d"}, {"f", "g"}]
How would you do this using a stream approach?
This is what I tried:
List numbers = reader.lines().map(s -> s.split("[\\W]")).collect(Collectors.toList());
This does not work. My IDE provides the following feedback:
Incompatible types. Required List but 'collect' was inferred to R: no instance(s) of type variable(s) T exist so that List<T> conforms to List
It shows... I am still trying to figure streams out.