title: Storing object into an array - Java
body: <p>I am relatively new to Java and I have taken some light courses on it. I am trying to emulate an exercise that I had a while back and I am having some trouble. </p>
  
  <p>I have two classes. One is taking in data and the other is storing it. </p>
  
  <pre><code>public class Car{
  
  public Car(String name, String color)
  {
       this.name = name,
       this.color = color
  }
  </code></pre>
  
  <p>How can I store this into the array (not an array list) that I created in this class:</p>
  
  <pre><code>public class CarDatabase {
  
  Car[] carList = new Car[100];
  
  public CarDatabase()
  {
      // System.out.println("test");
  }
  
  public void createAccount(String name, String color)
  {        
  // this is where I am having trouble
  
  
      for (int i = 0; i &lt; carList.length; i++)
      {
  
      System.out.println("Successfully created: " + name + 
              "." + "Color of car: " + color);
      break;
  
  
      }
  }
  </code></pre>
  
  <p>I don't have a main method yet but I will need one later on to for example, PRINT out this array and that is what I can't wrap my head around -     how do I store DATA/OBJECTS into the "CarDatabase" array so I can call methods with it later (instead of just being able to print it)?</p>
  
  <p>Any help would be appreciated.
  Thanks!</p>