title: Using an ArrayList to add new objects in java?
body: <p>I'm having trouble understanding an ArrayList. I am writing a program using 3 classes Customer, Video, and Invoice.  In the code below I am creating a new customer to add to set ArrayList but I feel I am trying to treat it as if it were an array. I want the user to be able to add another customer object and use a counter "i" and run through the series of questions to add to that customer object. i realize some of this is quite a mess. </p>
  
  <pre><code>import java.util.Scanner;
  import java.util.ArrayList;
  
  public class Prog4 {
  
  
      public static void main(String[] args)
      {
          Scanner in = new Scanner(System.in);
          ArrayList &lt;Customer&gt; customer = new ArrayList &lt;Customer&gt;();
          int i = 0;
          char ans;
  
          do
          {
  
              System.out.print("Customer name: ");
              String name = in.next();
              customer.add(i,).setName(name);
  
              System.out.print("Street Address: ");
              String streetAddress = in.next();
              d1.setStreetAddress(streetAddress);
  
              System.out.print("City: ");
              String city = in.next();
              d1.setCity(city);
  
              System.out.print("State: ");
              String state  = in.next();
              d1.setState(state);
  
              System.out.print("Zipcode: ");
              String zipcode = in.next();
              d1.setZipcode(zipcode);
  
              System.out.print("Phone Number: ");
              String phoneNumber = in.next();
              d1.setPhoneNumber(phoneNumber);
  
              customer[i] = new Customer(name, streetAddress, city, state, zipcode, phoneNumber);
  
              System.out.print("Would you like to enter in a new customer (y/n)? ");
              String answer = in.next();
              ans = answer.charAt(0);
          }while(ans == 'y');
  
  
      }
  
  }
  </code></pre>