title: Where/how to create new object in loop
body: <p>Say that I have a textfile that Im looping through each line in. The text files lines look like this:</p>
  
  <pre><code>1
  2
  3
  4
  
  1
  2
  3
  4
  
  1
  2
  3
  4
  </code></pre>
  
  <p>I also have a class called DataHolder that I want a new instance of with each segment (where a segment is the lines 1 2 3 4). The DataHolder class has variables for 1 2 3 and 4. When the iterator hits the whitespace, a new object of the DataHolder class should be created for the next 1 2 3 4. </p>
  
  <p>How can I accomplish this ? This is what I have at the moment</p>
  
  <pre><code>File theFile = new File(pathToFile);
  try
  {
      Scanner fileContent = new Scanner(theFile);
      DataHolder data = new DataHolder();
      while(fileContent.hasNextLine())
      {
          String line = fileContent.nextLine();
          if(line == "")
          {
  
          }
      }  
  }
  catch(Exception e)
  {
      // ToDo
  }
  </code></pre>