Revert "Stream test"

This commit is contained in:
eugenefischer
2020-06-11 14:03:27 -05:00
committed by GitHub
parent 87cf8a3e05
commit 435a9ef718
12 changed files with 47 additions and 88 deletions

View File

@@ -12,17 +12,6 @@ class RandomNumberFileReader{
private ArrayList<Integer> numbers = new ArrayList<Integer>();
public RandomNumberFileReader(String file){
//reads text from file of integers, one on each line
//uses try-with-resources loop to automatically close BufferedReader
//uses Stream operations instead of while loop
try(BufferedReader reader = Files.newBufferedReader(Path.of(file));){
reader.lines().mapToInt(Integer::parseInt).forEach(num -> numbers.add(num));
}catch (IOException ex){
System.err.println(ex);
}
/*
//previous version retained for reference
//Reads in from a text file of integers, one on each line
try{
BufferedReader reader = Files.newBufferedReader(Path.of(file));
@@ -34,9 +23,8 @@ class RandomNumberFileReader{
} catch (IOException ex){
System.err.println(ex);
}
*/
}
public ArrayList<Integer> getNumbers(){
return numbers;
}