title: If condition inside nested for loop in android
body: <p>I have two <code>ArrayList</code>s of the same model class (i.e <code>ListA</code> and <code>ListB</code>) to which I have added the same data.
  Then I added some data only in the second arraylist <code>ListB</code>.</p>
  
  <p>Now, I want to fetch only that data which is different in both <code>ListA</code> and <code>ListB</code> and store the result in a third arraylist <code>ListC</code>.</p>
  
  <p>I tried below code. However, <em>all</em> elements are stored in <code>ListC</code>, as opposed to only those that are different:</p>
  
  <pre><code>ArrayList&lt;C&gt; ListC = new ArrayList&lt;&gt;();
  
  for (int i = 0; i &lt; ListA.size(); i++) {
  
      for (int j = 0; j &lt; ListB.size(); j++) {
  
          if (ListA.get(i).getName() == ListB.get(j).getName()) {
  
              Log.e("Do", "Nothing");
  
          } else {
              C c = new C(b.get(j).getName());
              ListC.add(c);
          }
      }
  }
  </code></pre>
  
  <blockquote>
    <p>Edited Question</p>
  </blockquote>
  
  <pre><code>ArrayList&lt;Model&gt; a = new ArrayList&lt;&gt;();
  Model model = new Model();
  model.setName("MaHi");
  model.setAge("20");
  a.add(model);
  
  ArrayList&lt;Model&gt; b = new ArrayList&lt;&gt;();
  Model model = new Model();
  model.setName("MaHi");
  model.setAge("20");
  b.add(model);
  Model model2 = new Model();
  model2.setName("Ritu");
  model2.setAge("21");
  b.add(model2);
  
  ArrayList&lt;Model&gt; c=new ArrayList&lt;&gt;();
  </code></pre>
  
  <p>now I want to fetch that data which is not in either arraylist a or arraylist b (i.e. data of model2) into arraylist of c;</p>