title: How to prevent the adding of duplicate objects to an ArrayList
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/9962082/prevent-duplicate-entries-in-arraylist">Prevent duplicate entries in arraylist</a>  </p>
  </blockquote>
  
  
  
  <p>I have an arraylist of a particular class C. </p>
  
  <pre><code>List&lt;C&gt; myList = new ArrayList&lt;C&gt;();
  </code></pre>
  
  <p>Class C has two attributes viz. </p>
  
  <pre><code>String str1;
  String str2;
  </code></pre>
  
  <p>Now as and when I am adding objects of type C to the ArrayList myList, I want to check if there already exists an object in the list with the values of str1 and str2 matching the values of the parameters (str1 and str2) of the object I am about to add.</p>
  
  <p>Is there any efficient way to do this without having to iterate everytime through the complete list and checking for matching between the parameters?</p>