title: Android check if value equals to the values in Array
body: <p>I have a ArrayList tokens; I am adding values to the array with a listView click. 
  Before i add the value to array i check if the value already exist array. 
  I remove the value is it exists else i will add the the value</p>
  
  <p>This is how i have done, but the values are not being added to the array</p>
  
  <pre><code>ArrayList&lt;String&gt; tokens;
  tokens = new ArrayList&lt;String&gt;();
  ...
  ....
  public void onItemClick(AdapterView&lt;?&gt; listView, View view,
                              int position, long id) {
          Cursor cursor = (Cursor) listView.getItemAtPosition(position);
          String selectedtoken = cursor.getString(cursor.getColumnIndexOrThrow("ContactToken"));
  
          for (int i = 0; i &lt; tokens.size(); i++) {
                  if (tokens.get(i).equals(id_To_Search)) {
                      tokens.remove(i);
                  }
                  else {
                      tokens.add(selectedtoken );
                  }
              }
      }
  ...
  ...
  Log.i("array: ", tokens.toString()); // No values in the array
  </code></pre>