title: check if a value already exists in a Hash Map
body: <p>have a method in which I'm trying to iterate through the values of a HashMap and to check if they match a specific string - if they do, then I want the method to return false. I had a look at a few topics and this is what I've come up with although it does not seem to work: </p>
  
  <pre><code>class Person { 
  
  public int check(String newName, String newNumber) {
  
          for (Person recordObject : map.values()) {
  
              if (map.get(recordObject) != null
                      &amp;&amp; map.get(recordObject).toString().equals(newNumber)) {
  
                  return 0;
              }
          }
  
          map.put(newName, newNumber);
          return 1;
      }
  }
  </code></pre>
  
  <p>At the moment my program always creates a record for some person, even if they have already been added to the map so it does not actually go into the if of the check method.</p>