title: Iterate over array of objects Java
body: <p>So, I have a class Model01:</p>
  
  <pre><code>public class Model01 {
  
  private String color;
  private String name;
  private String bl;
  
      public String getColor() {
      return color;
  }
  
  
  public void setColor(String color) {
      this.color = color;
  }
  
  public String getName() {
      return name;
  }
  
  
  public void setName(String color) {
      this.name = name;
  }
  
  public String getBl() {
      return bl;
  }
  
  
  public void setBl(String color) {
      this.bl = bl;
  }
  </code></pre>
  
  <p>At a certain point in my code I want to map some data I receive from the database onto this model class like this:</p>
  
  <pre><code>List&lt;Model01&gt; resultEntries = new ArrayList&lt;Model01&gt;();
  for(Object[] i : res){ // res is the result of my query
  Model01 m = new Model01();
     m.setColor((String) item[0]);
     m.setName((String) item[1]);
     m.setBl((String) item[2]);
   resultEntries.add(m)
  }
  </code></pre>
  
  <p>Later on in my code I want to iterate over my array of resultEntries, which contains many objects and I want to compare some fields between my objects. I've done it something like this, but it seems that it only iterates over my last object. What am I doing wrong ?</p>
  
  <pre><code>for(Model01 i : resultEntries){
  if (i.getName.equals(i.getBl))
  ...
  System.out.println(...);
  }
  </code></pre>
  
  <p><strong>EDIT:</strong> I am always instantiating a new Model01 object and these code snippets are actually inside a function that performs some queries to the database and everytime the method is called a new object will be created with new values inside the for.</p>