title: HashMap.containsKey() - how to search for a class?
body: <p>Hello<br>
  if you search in an <code>HashMap&lt;String,String&gt;</code> for a specific value of a key-value-pair, you can write the following:  </p>
  
  <pre><code>myHashMap.containsKey(myString);
  </code></pre>
  
  <p>But how can I manage it if the key is not a string? I have a class which looks like this:</p>
  
  <pre><code>public class Kategorie implements Comparable {
      private String name;
  
      public Kategorie()  {
          super();
      }
  
      public Kategorie(String name)  {
          setName(name);
      }
  
      public String getName() {
          return name;
      }
  
      public void setName(String name) {
          this.name = name;
      }
  
      @Override
      public int compareTo(Object o) {
          if (!(o instanceof Kategorie))  
             throw new ClassCastException();
  
          Kategorie k = (Kategorie)o;
          String name = k.getName();
          return this.getName().compareTo(name);
  
      }
  }
  </code></pre>
  
  <p>In a map I saved keys and values of this type "Kategorie".</p>
  
  <pre><code>mapKategorieDEundEN.put(new Kategorie(strName_de), new Kategorie(strName_en));
  </code></pre>
  
  <p>Later in the code, I want to check if there is a key with a specific string.</p>
  
  <pre><code>if (mapKategorieDEundEN.containsKey(searchString))  {
  </code></pre>
  
  <p>...doesn't work, because the key is not a string but a "Kategorie", that's clear.</p>
  
  <p>Then I tried something like this:</p>
  
  <pre><code>if (mapKategorieDEundEN.containsKey(new Kategorie(searchString)))  {
  </code></pre>
  
  <p>...doesn't work too. I assume that it doesn't find anything because the object is not the "original" object but a new one.</p>
  
  <p>In this case, can I use containsKey at all or do I have to use a loop over the HashMap?</p>