title: ArrayList Remove Duplicate Elements
body: <p>I am parsing JSON data into ListView using <code>ArrayList</code> and now i would like to know How do i <code>remove duplicate</code> entries from ArrayList before populating it into <code>ListView</code>.</p>
  
  <p>Here is my <strong>JSON</strong>:</p>
  
  <pre><code>{
    "data": [
      {
        "city": "Delhi"
      },
      {
        "city": "Mumbai"
      },
      {
        "city": "Delhi"
      },
      {
        "city": "Mumbai"
      }    
    ]
  }
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/6Rl6R.png" alt="enter image description here"></p>
  
  <p><strong>MainActivity.java</strong></p>
  
  <pre><code>public class MainActivity extends Activity {
  
      ArrayList&lt;Destination&gt; destinationArrayList;    
      MainAdapter adapter;
      EditText editText;
      Destination destination;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          editText = (EditText) findViewById(R.id.editLocation);
  
          destinationArrayList = new ArrayList&lt;Destination&gt;();
  
          new JSONAsyncTask().execute("my api link");
  
          ListView listview = (ListView)findViewById(R.id.list);
          adapter = new MainAdapter(getApplicationContext(), R.layout.row, destinationArrayList);
  
          listview.setAdapter(adapter);                       
      }
  
  
      class JSONAsyncTask extends AsyncTask&lt;String, Void, Boolean&gt; {
  
          @Override
          protected void onPreExecute() {
              super.onPreExecute();
          }
  
          @Override
          protected Boolean doInBackground(String... urls) {
              try {
                  ....
                  if (status == 200) {
                      HttpEntity entity = response.getEntity();
                      String data = EntityUtils.toString(entity);
  
                      JSONObject jsono = new JSONObject(data);
                      JSONArray jarray = jsono.getJSONArray("data");
  
                      for (int i = 0; i &lt; jarray.length(); i++) {
                          JSONObject object = jarray.getJSONObject(i);
  
                          destination = new Destination();                                                
                          destination.setCity(object.getString("city"));                          
                          destinationArrayList.add(destination);
  
                      }
                      return true;
                  }
  
              ......
              return false;
          }
  
          protected void onPostExecute(Boolean result) {
              adapter.notifyDataSetChanged();             
          }
      }
  
  }
  </code></pre>