import java.util.Scanner;
import java.io.*;
import java.util.ArrayList;
public class Test
{
public static void main (String args[]) throws java.io.IOException
{
Scanner s = new Scanner(new File("filepath"));
ArrayList<Integer> list = new ArrayList<Integer>();
while (s.hasNext()){
if(s.hasNextInt()){
list.add(s.nextInt());
}
}
s.close();
System.out.println(list);
}
}
I'm trying to read only integers from a text file that has the following format per line: text integer text.
This is what I have so far but when I compile and run it prints never ending [] for whatever reason.
Please note that I changed the filepath just for uploading it to here, that is not the issue.