I am writing a small program that collects information from a text file, in which the information on each line is separated by |. I’ve written a file reader class that creates an object with data members corresponding to the information on each line, then the object is put into an ArrayList.
Now I want to perform data analysis using the objects in the ArrayList, say, I want to find the average value of a specific attribute. Is it preferable to use a loop that traverses each element in the ArrayList and add the attribute value into a variable, then get the average using [totalValue variable] / [ArrayList size]?
The file I have here has over 60,000 lines. And I don’t just want to do averaging. Are there any performance issues? Thanks so much.
Computing the average necessarily requires looking at every element. Thus there is nothing wrong with using a loop.
Also bear in mind that for this type of computation, 60K elements is nothing.