title: Removing object from ArrayList without knowing index
body: <p>Let's say i have ArrayList of 10 cars and i want to remove car at index 6 from my list. How should my removeCar function looks like if my existing code is:</p>
  <pre><code>public class Main {
  
      public static void main(String[] args) {
          
          Car C1 = new Car();
          C1.addCar(&quot;audi&quot;, 5);
          C1.addCar(&quot;porsche&quot;, 3);
  
          C1.removeCar(&quot;audi&quot;); // is not working
          
  }
  
  public class Car {
  
      private String name;
      private int age;
  
      private ArrayList&lt;Car&gt; cars;
  
      public Car() {
          this.cars = new ArrayList&lt;&gt;();
      }
  
      public Car(String name, int age) {
          this.name = name;
          this.age = age;
      }
  
      public void addCar(String name, int age) {
          this.cars.add(new Car(name, age));
      }
  
      public void removeCar(String name) {
          this.cars.remove(name);
      }
  
        public ArrayList&lt;Car&gt; getCars() {
          return cars;
      }
  }
  </code></pre>
  <p>How to change remove method to be able to remove cars from ArrayList by their name?</p>