title: Duplicates in Arraylist, comparing various fields java
body: <p>I have a code to return an arrayList with the duplicates of an ArrayList
  but seems it's not working, I am comparing all items in the array...</p>
  
  <pre><code>public ArrayList&lt;ObjectList&gt; duplicates(ArrayList&lt;ObjectList&gt; someObjectsList) {
  
      ArrayList&lt;ObjectList&gt; ret = new ArrayList&lt;ObjectList&gt;();
      for ( ObjectList aSomeObjectsList: someObjectsList) {
  
          String field1 = aSomeObjectsList.get1();
          String field2 = aSomeObjectsList.get2();
          String field3 = aSomeObjectsList.get3();
          String field4 = aSomeObjectsList.get4();
          for (ObjectList someObject : ret) {
              if (
                  field1.trim().equals(someObject.get1())&amp;&amp; 
                  field2.trim().equals(someObject.get2())&amp;&amp;
                  field3.trim().equals(someObject.get3())&amp;&amp;
                  field4.trim().equals(someObject.get4())     
                  ){
                  ret.add(aSomeObjectsList);
  
              }
          }
  
      }
      return ret;
  } 
  </code></pre>
  
  <p>But i guess I am doing something wrong because it doesn't return anything, and I know it has duplictates under this 4 field criteria</p>
  
  <p>Thanks in advance</p>