I'm trying to populate a numbers array of long numbers (as well as a temp array of the same numbers) by reading in a file. The file is about 32000 lines of various long numbers (one per line). The code provided by my professor looks like this:
public static void main(String[] args) throws FileNotFoundException {
Scanner in = new Scanner(new File("longNumbers.txt"));
Long [] numbers;
Long [] temp;
Long startTime, endTime;
while(in.hasNext()) {
//TODO: populate numbers and temp arrays
}
With the work implied to be done within the while loop provided. My question is this: isn't an array's size fixed? And if we haven't scanned in every line before populating the array, how do we know what the size of the arrays will be? I'm very confused as to how these two arrays should be populated/instantiated while checking each line.
Listat first and then convert it to an array after. Other options would be to use the new streams somehow (haven't looked into them as much)