title: find and replace object from list with certain attribute already not exists
body: <p>I have a List where some Objects are being stored.I would like  to remove an object from list with certain attribute already not exists.My sample code is, here please help me.</p>
  
  <pre><code>public class Mysamples {
  
      private void example() {
          List&lt;SomeType&gt; listWithDuplicates = new ArrayList&lt;SomeType&gt;();
  
          SomeType someObject1 = new SomeType("hello", "1");
          SomeType someObject2 = new SomeType("hello", "2");
   }
  
  private void removeDuplicates(List&lt;SomeType&gt; listWithDuplicates) {
      /* Set of all attributes seen so far */
      Set&lt;String&gt; attributes = new HashSet&lt;String&gt;();
      /* All confirmed duplicates go in here */
      List duplicates = new ArrayList&lt;SomeType&gt;();
  
      for (SomeType x : listWithDuplicates) {
          if (attributes.contains(x.getName())) 
          {
              duplicates.add(x);
          }
          attributes.add(x.getName());
      }
  
      System.out.println(duplicates);
     // System.out.println(attributes);
  }
  
  public static void main(String[] args) {
      // TODO code application logic here
      List&lt;SomeType&gt; listWithDuplicates = new ArrayList&lt;SomeType&gt;();
      SomeType someObject1 = new SomeType("hello", "1");
      SomeType someObject2 = new SomeType("hello", "2");
      SomeType someObject3 = new SomeType("hello", "1");
      SomeType someObject4 = new SomeType("hello1", "2");
      SomeType someObject5 = new SomeType("hello1", "1");
      SomeType someObject6 = new SomeType("hello2", "2");
  
  
      listWithDuplicates.add(someObject1);
      listWithDuplicates.add(someObject2);
      listWithDuplicates.add(someObject3);
      listWithDuplicates.add(someObject4);
      listWithDuplicates.add(someObject5);
      listWithDuplicates.add(someObject6);
      Mysamples s = new Mysamples();
  
      s.removeDuplicates(listWithDuplicates);
  }
  }
  </code></pre>
  
  <p>*<strong><em>The out put is</em>*</strong></p>
  
  <pre><code>[SomeType{name=hello, id=2}, SomeType{name=hello, id=1}, SomeType{name=hello1, id=1}]
  </code></pre>
  
  <p><strong>but i want the out put like</strong></p>
  
  <pre><code>[SomeType{name=hello, id=1,SomeType{name=hello, id=2}, SomeType{name=hello, id=1}} SomeType{name=hello1, id=2},SomeType{name=hello1, id=1}]]
  </code></pre>