title: comparing elements of two arrayList in java
body: <p>i got two String type arraylist ..one list containing “book1”, “book2”, “book3” and “book4”. And another arrayList contains “book1”, “book2”, “book3”. So, size of first list is 4 and second is 3. And I created another arrayList  equal to the size of first list</p>
  
  <pre><code>List&lt;Integer&gt; comparingList = new ArrayList&lt;Integer&gt;();
                      //adding default values as one
                      for(int a=0;a&lt;firstList.size();a++){
                          comparingList.add(0);
  
                      }
  </code></pre>
  
  <p>And if any content is equal between two lists, I’m setting 1 instead of 0.</p>
  
  <p>so the new arrayList(comparingList) should have 1,1,1,0 elements</p>
  
  <pre><code>for(int counter = 0;counter &lt; firstList.size();counter++){
  for(int counter1 = 0;counter1 &lt; secondList.size();counter1++){
  if(firstList.get(counter).equals(secondList.get(counter1))){
      comparingList.set(counter,1);
      break;
  }
  }
  
  }
  </code></pre>
  
  <p>but when i do this, i’m not being able to set 1 as I can’t get into if condition, can anyone help me please</p>