title: Comparing line by line of a CSV file Java
body: <p>A sample of my code is as follows: </p>
  
  <pre><code>File myFile = new File("C:\\Windows\\Temp\\fileName.csv");
  
  try {
      Scanner myScanner = new Scanner(myFile);
      while(myScanner.hasNextLine()) {
          String data = myScanner.nextLine();
          String[] fields = data.split(",");
          name = fields[0];
          age = Integer.parseInt(fields[1]);
          birthday = fields[2]; 
          storeVisitDate = fields[3];
          }
          Person myPerson = new Person(name,age,birthday,storeVisitDate);
      } 
  }
  </code></pre>
  
  <p>I have a separate class called "Person", which instantiates an object based on the input of the CSV file.</p>
  
  <p>What I am tasked to do is to prepare an output that generates the name, age, birthday and store visit date of a person on one line, however, if this person has multiple store visit dates, I should only display the store visit date in the following line.</p>
  
  <p>How am I able to compare the current line to the next line to see if it is the same name of the person?
  Also, I am not allowed to create any ArrayLists/Lists.</p>
  
  <p>Sample of .CSV file contents:
  <a href="https://i.stack.imgur.com/4uH0M.png" rel="nofollow noreferrer">Sample of .CSV file contents</a></p>
  
  <p>Thank you. </p>
  
  <p>Person Class:</p>
  
  <pre><code>public class Person{
  private String name;
  private int age;
  private String birthday;
  private String dateOfVisit;
  
  public Person(String data)
  {
  String[] info = data.split(",");
  name = info[0];
  age = Integer.parseInt(info[1]);
  birthday = info[2];
  dateOfVisit = info[3];
  }
  }
  </code></pre>