title: ArrayList from class objects simpler way to do?
body: <p>I know how to put class objects to an <code>ArrayList</code> in java (since new objects can be appended without knowledge of an index first) but I was wondering if there is a simpler way of adding them to an <code>ArrayList</code> and iterating over them?</p>
  <p>I was even thinking that, hypothetically, if I kept my object names in a pattern, that I should be able to add each object to the list using a loop e.g. <code>car1, car2, car3, ...</code></p>
  <pre><code>import java.util.ArrayList;
  
  public class TestCar {
          
      public static void main(String[] args) {
          ArrayList&lt;String&gt; carNames = new ArrayList&lt;&gt;();
          // Cars have simple getter methods corresponding with String and int
          Car car1 = new Car(&quot;Rav4&quot;, 2017);
          carNames.add(car1.getName());
          Car car2 = new Car(&quot;Commodore&quot;, 2005);
          carNames.add(car2.getName());
  
          for (int i = 0; i &lt; carNames.size(); i++) {
              System.out.println(carNames.get(i));
          }
  
      }
  }
  </code></pre>
  <p>As always, thanks for any replies!</p>