I am reading a huge number of integers from a file, and in the end I want to get basic statistics from these Integers (median, average, 25th, 75th, etc.). I could calculate some of these statistics on the go, but it seems to me that calculating the 25th / 75th percentile would be difficult. The simplest approach, I think, would be to put Integers on a list and make statistics from that list. However, since the list is so large, it can slow down the program to use a large amount of memory. Do you have any suggestions? This is how I get the data and the two options I was thinking about:
Scanner input = new Scanner(new File("name")); ArrayList<Integer> lits= new ArrayList<Integer>(); while(input.hasNextLine()){ list.add(Integer.parseInt(input.nextLine())); } doStatistics(list);
OR
Scanner input = new Scanner(new File("name")); while(input.hasNextLine()){ //I dont know how I would acomplish this for the percentile stats acqquireStats(Integer.parseInt(input.nextLine())); }
source share