I have a .txt file with this content: "17.23;12.1;20.34;88.23523;".
I want to read this file as doubles into an ArrayList. And eventually print the ArrayList (and eventually print the min. and max., but I don't think that will be a problem after solving this).
But I only get the output "[ ]".
What am I doing wrong? I've been struggling with this for embarrassing 15+ hours, browsed here, youtube, course books...
My code:
public static void main(String[] args) throws IOException {
File myFile = new File("text.txt");
Scanner scan = new Scanner(myFile);
ArrayList<Double> aList = new ArrayList<>();
while (scan.hasNextDouble()) {
double nextInput = scan.nextDouble();
if (nextInput != 0) {
break;
}
aList.add(nextInput);
}
System.out.println(alist);
}