title: How to use indexOf on a List containing HashMap with multiple key/value pairs
body: <p>I have a <code>List</code> containing <code>HashMaps</code>. Each <code>HashMap</code> in the list might have multiple <code>key/value</code> pairs. I want to <code>indexOf</code> on the list to find out the index of the element where the passed in HashMap is. However, the problem is that e<a href="http://docs.oracle.com/javase/6/docs/api/java/util/Map.html#equals%28java.lang.Object%29" rel="nofollow">quals method of HashMap</a> looks at all the entire <code>entrySet</code> while comparing. Which is not what I want. </p>
  
  <p>Example:</p>
  
  <pre><code>    List&lt;HashMap&gt; benefit = new ArrayList&lt;HashMap&gt;();
      HashMap map1 = new HashMap();
      map1.put("number", "1");
      benefit.add(map1);
      HashMap map2 = new HashMap();
      map2.put("number", "2");
      map2.put("somethingelse", "blahblah"); //1
      benefit.add(map2);
  
      HashMap find = new HashMap();
      find.put("number", "2");
      int index = benefit.indexOf(find);
      if (index &gt;= 0)
          System.out.println(benefit.get(index).get("number"));
  </code></pre>
  
  <p>The above code does not print anything because of line with <code>//1</code>. </p>
  
  <ul>
  <li>What do I have to do so that the above code actually prints <code>2</code>? </li>
  <li>Is there a way to implement comparable on the list so that I can define
  my own?</li>
  </ul>