remove empty strings
This commit is contained in:
@@ -14,13 +14,16 @@ public class RandomWordFileReader {
|
|||||||
public RandomWordFileReader(String filename){
|
public RandomWordFileReader(String filename){
|
||||||
try(BufferedReader reader = Files.newBufferedReader(Path.of(filename));){
|
try(BufferedReader reader = Files.newBufferedReader(Path.of(filename));){
|
||||||
//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
|
//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\\W_]+"))).forEach(word -> words.add(word.toLowerCase()));
|
reader.lines().flatMap(line -> Arrays.stream(line.split("[\\W\\s\\n_ ]+"))).forEach(word -> words.add(word.toLowerCase()));
|
||||||
}catch (IOException ex){
|
}catch (IOException ex){
|
||||||
System.err.println(ex);
|
System.err.println(ex);
|
||||||
}
|
}
|
||||||
/*for (String e : words) {
|
for (int i = 0; i < words.size(); i++) {
|
||||||
e = e.replaceAll("\\W+","");
|
if (words.get(i).matches("")) {
|
||||||
}*/
|
words.remove(i);
|
||||||
|
i--;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public ArrayList<String> getWords(){
|
public ArrayList<String> getWords(){
|
||||||
|
|||||||
Reference in New Issue
Block a user