title: How can I flag duplicates in an array?
body: <p>I would like to know a method for flagging values in an array, removing the duplicates and combining some of the data <strong>in Java</strong>.</p>
  
  <p>I am keeping a record of geo locations using lat, long and description this is encoded in a JSON array as follows:</p>
  
  <pre><code>[{"lon": 0.001, "lat": 0.001, "desc": test}, {"lon": 0.001, "lat": 0.001, "desc": test2}]
  </code></pre>
  
  <p>I would like to be able to remove the duplicate geo locations while keeping the "desc" part of the array, e.g.</p>
  
  <pre><code>[{"lon": 0.001, "lat": 0.001, "desc": test, test2}]
  </code></pre>
  
  <p><strong>Edit</strong>:
  This is what I am currently doing:</p>
  
  <pre><code>//Store locPoints from server in JSONArray
  JSONArray jPointsArray = new JSONArray(serverData); 
  List&lt;JSONObject&gt; jObjects = new ArrayList&lt;JSONObject&gt;();
  List&lt;JSONObject&gt; seenObjects = new ArrayList&lt;JSONObject&gt;();
  
   for(int i = 0; i &lt; jPointsArray.length(); ++i)
  {
   jObjects.add(jPointsArray.getJSONObject(i));
  }        
   for (JSONObject obj : jObjects) 
                  {
                      //This always returns true
                      if (!seenObjects.contains(obj))// &amp;&amp; !seenObjects.contains(obj.get("lon")))
                      {
  
                          Log.i("Sucess", "Huzzah!");
                          seenObjects.add(obj);
                      }
                      else 
                      {
                           //merge the 'desc' field in 'obj' with the 'desc' field in
                           JSONObject original = (JSONObject)seenObjects.get(seenObjects.indexOf(obj));
                           JSONObject update = obj;
                           original.put("desc", original.get("desc") + ", " + update.get("desc"));
                           seenObjects.get(seenObjects.indexOf(obj)).get("desc"));
  
                      }
                  }
  </code></pre>