title: Java ArrayList Output Error
body: <p>In this program, I am getting incorrect output for the ArrayList.
  In the first line, it always prints every single element of the ArrayList horizontally.
  It then will correctly print the ArrayList.
  Can someone take a look at the code and see if I did something wrong? I will show you the two classes.</p>
  
  <p>Class 1:</p>
  
  <pre><code> public class contactDriver
   {
   public static void main (String[] args)
   {                       
             Scanner scan = new Scanner(System.in);
  
             System.out.println ("What would you like to do?");  
             int answer;
             System.out.println ("Press 1 to add a contact.");          
             System.out.println ("Press 2 to display all contacts.");
  
             answer = scan.nextInt();
  
             ArrayList&lt;Contact&gt; contacts = new ArrayList&lt;Contact&gt;();
  
          contacts.add(new Contact("Patrick McGee", "334-555-8860", "pmcgee123@gmail.com"));
          contacts.add(new Contact("John Appleseed", "142-555-6740", "jappleseed99@gmail.com"));
          contacts.add(new Contact("Matt Jordan", "213-555-2323", "mjordan23@gmail.com"));
          contacts.add(new Contact("Kanye East", "255-434-9909", "keast123@gmail.com"));
          contacts.add(new Contact("Derrick Flower", "144-555-1111", "dflower1@gmail.com"));
  
             if (answer == 1){
                System.out.println ("Please enter the first and last name of the contact.");
                String name = scan.next();
                scan.nextLine();
  
                System.out.println ("Please enter the phone number of the contact.");
                String num = scan.next();
                scan.nextLine();
  
                System.out.println ("Please enter the email of the contact.");
                String email = scan.next();
                scan.nextLine();
  
                contacts.add(new Contact(name, num, email));
  
                }
  
             if (answer == 2){
                }
                System.out.println(contacts);
                for(Contact c : contacts) {
                System.out.println(c);
  </code></pre>
  
  <p>Class 2:</p>
  
  <pre><code> public class Contact
  {
  public Contact(String name, String num, String email)
  {
    this.name = name;
    this.num = num;
    this.email = email;
  }
  
  public String getFirstname()
  {
    return name;
  }
  
  public String getNum()
  {
    return num;
  }
  
  public String getEmail()
  {
    return email;
  }
  
  
  public String toString()
  {
    return "Contact[" + name + ", " + num + ", " + email + "]";
  }
  
  private String name;
  private String num;
  private String email;
  
  }
  </code></pre>
  
  <p><strong>The output:</strong></p>
  
  <p>[Contact[Patrick McGee, 334-555-8860, pmcgee123@gmail.com], Contact[John Appleseed, 142-555-6740, jappleseed99@gmail.com], Contact[Matt Jordan, 213-555-2323, mjordan23@gmail.com], Contact[Kanye East, 255-434-9909, keast123@gmail.com], Contact[Derrick Flower, 144-555-1111, dflower1@gmail.com]<br>
  (all in one line).</p>
  
  <p><strong>Then prints:</strong><br>
                                                                                       Contact[Patrick McGee, 334-555-8860, pmcgee123@gmail.com]<br>
  Contact[John Appleseed, 142-555-6740, jappleseed99@gmail.com]
  ... so on.</p>
  
  <p>Any ideas on the fix?</p>
  
  <p>Thanks :)</p>