title: Compare HashMap values in an ArrayList
body: <p>I have an <code>ArrayList</code> and there are some <code>HashMap&lt;String, String&gt;</code> in this. So, I want to compare for same values in the maps. When I find same values then I want to keep one map of them. For example, consider that second map and fifth map (in the arraylist) have the same value. I want to keep the second map and remove the fifth from the arraylist.
  i try to do with an iterator, but i can't do it. It seems complicated. Can you give me an example?</p>
  
  <p>This is my last try: </p>
  
  <pre><code>private HashMap&lt;String, String&gt; mapValues = new HashMap&lt;String, String&gt;();
  private HashMap&lt;String, String&gt; mapValues2 = new HashMap&lt;String,String&gt;(); 
  private HashMap&lt;Integer, String&gt; mval = new HashMap&lt;Integer, String&gt;();
  
  //i take the ArrayList with the maps for comparison private
  ArrayList&lt;HashMap&lt;String, String&gt;&gt; check(ArrayList&lt;HashMap&lt;String, String&gt;&gt; list) {           
  
   //a new ArrayList. It will have the maps(HashMap&lt;key, value&gt;) with no same values.
   ArrayList&lt;HashMap&lt;String, String&gt;&gt; listFinal = new ArrayList&lt;HashMap&lt;String, String();
  
      for (int i = 0; i &lt; list.size(); i++) {
          mapValues = list.get(i);
          mval.put(i, mapValues.get("value"));
      }
  
      for (int i = 0; i &lt; mval.size(); i++) {
          HashMap&lt;String, String&gt; newMapValues = new HashMap&lt;String, String&gt;();
          mapValues2 = list.get(i);
          String iVal = mapValues2.get("value");
          newMapValues = list.get(i);
          int flag = -1;
          int remove = -1;
  
          for (int j = i+1; j &lt; mval.size()-1; j++) {
              String jVal = mval.get(j);
              if (val.compareTo(jVal) == 0) {
                  flag = i;
                  remove = j;
              }
          }
          if (flag == -1) {
              listFinal.add(newMapValues );
          } else if (flag != -1) {
              listFinal.remove(remove);
          }   
      }
  }
  </code></pre>