title: how to return value in a method in Java
body: <p>I got a question about how to return values when the method invoked in main method, here is my partial code:</p>
  
  <pre><code> import java.util.ArrayList;
  
  
  public class Race {
  
  private ArrayList&lt;Car&gt;cars;
  
  
   public Race(){
  cars=new ArrayList&lt;Car&gt;();
  }
  
  public Car find(double position){
  for(Car d:cars){
      if(d.getPosition()==position){
          return d;
      }
  }
  return null;
  }
   .................
  </code></pre>
  
  <p>When I called the find method in main class:</p>
  
  <pre><code>     public class Test {
  
  public static void main(String[] args) {
  
      Race race=new Race();
      Car mazda=new Car("Mazda",1.0,1.0,2.0,2.0);
      Car honda=new Car("Honda",1.0,1.0,1.0,2.0);
      race.addCars(mazda);
      race.addCars(honda);
  
       System.out.println(race.find(1.0).getName());
  </code></pre>
  
  <p>The third values are position, which means mazda and honda have the same position and it is supposed to print both, but when I run it, it only prints mazda, I am confused, please advise, cheers!</p>