title: how to ensure an arrayadapter does not accept duplicate values
body: <p>i have a custom arrayadapter with some pre_populated data and more data is to be added to it from  the user input.The problem is that  duplicate values are still added to the arrayadapter..here is my code:</p>
  
  <pre><code>String s;//holds data from user input
  
  for(int i=0 ; i&lt;my_adapter.getCount() ; i++){
   MyCollection itemObject=my_adapter.getItem(i);
   //MyCollection is an object from the collection class
   String c=itemObject.toString();
  
       if(c.matches(s)){
       //do not add s to array adapter
  
  }else{
     //add s to arrayadapter
      my_arrayvalues.add(new MyCollection(s));
      my_adapter.notifyDataSetChanged();
  }
  </code></pre>
  
  <p>Running the above code,no change is effected on the adapter even when the the values do not match..if i just run the project without including  the above
      duplicate values are added.how can i correct this?</p>
  
  <p>after following the answers i have done as suggested but still the duplicates are being added:
  <strong>the updated code</strong></p>
  
  <pre><code>             hs = new HashSet();
               my_arrayvalues.add(new MyCollections(s));
               hs.addAll(my_arrayvalues);
               my_arrayvalues.clear();
               my_arrayvalues.addAll(hs);
               my_adapter.notifyDataSetChanged();
  </code></pre>