title: Best way to read data from a file and store them
body: <p>I am reading data from a file of students where each line is a student, I am then turning that data into a student object and I want to return an array of student objects. I am currently doing this by storing each student object in an arraylist then returning it as a standard Student[]. Is it better to use an arraylist to have a dynamic size array then turn it into a standard array for the return or should I first count the number of lines in the file, make a Student[] of that size then just populate that array. Or is there a better way entirely to do this.</p>
  
  <p>Here is the code if it helps:</p>
  
  <pre><code>public Student[] readStudents() {
          String[] lineData;
          ArrayList&lt;Student&gt; students = new ArrayList&lt;&gt;();
          while (scanner.hasNextLine()) {
              lineData = scanner.nextLine().split(" ");
              students.add(new Student(lineData));
          }
          return students.toArray(new Student[students.size()]);
      }
  </code></pre>