From 84c3114726d4a1d4082673bbecca2cdaf8c4845b Mon Sep 17 00:00:00 2001 From: Eugene Fischer Date: Wed, 17 Jun 2020 17:30:08 -0500 Subject: [PATCH] fixing the streams --- Sorting/RandomWordFileReader.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Sorting/RandomWordFileReader.java b/Sorting/RandomWordFileReader.java index 86afc1d..85a8297 100644 --- a/Sorting/RandomWordFileReader.java +++ b/Sorting/RandomWordFileReader.java @@ -5,6 +5,7 @@ import java.nio.file.Files; import java.nio.file.Path; import java.io.BufferedReader; import java.io.IOException; +import java.util.Arrays; public class RandomWordFileReader { @@ -12,7 +13,8 @@ public class RandomWordFileReader { public RandomWordFileReader(String filename){ try(BufferedReader reader = Files.newBufferedReader(Path.of(filename));){ - reader.lines().forEach(word -> words.add(word)); + //This should use flatMap to make a string array from the line, and then turn the elements of that array into a stream, which goes to forEach + reader.lines().flatMap(line -> Arrays.stream(line.split("\\s+"))).forEach(word -> words.add(word)); }catch (IOException ex){ System.err.println(ex); }