Garmaine Staff asked 2 years ago

Say I had a file set up like this:

20 88.6

16 71.6

19.8 93.3

18.4 84.3

17.1 80.6

15.5 75.2

14.7 69.7

17.1 82

The two float values are separated by a space, say that the ones on the left are x values and the ones on the right are y values how would I read the file and store the x values in one array and the y values in another?

public static Float[] getData() throws FileNotFoundException {
    float data;
    List<Float> temps = new ArrayList<Float>();

    Scanner inFile = new Scanner(new File("cricket"));
    while(inFile.hasNext()) {

        data = inFile.nextFloat();


    for(int i = 0; i<=temps.size(); i++) {
    Float[] tempsArray = temps.toArray(new Float[0]);

    return tempsArray;


This is my code so far, I have all of the values in a single array, I'm not sure how to split them up.