title: can't delete an element from a hashmap
body: <p>I created a hashmap to store object Person, the key is a String (Person's email address).  I am trying to delete an entry in the hashmap using the key but not sure why it won't delete it. What went wrong?  My code and the output are included.  any help is appreciated!</p>
  
  <pre><code>import java.util.HashMap;
  import java.util.Map;
  
  public class TestHashMap {
  
      private Map &lt;String, Person&gt; personDB = new HashMap&lt;String, Person&gt;();
  
      // added main to test the code
      public static void main(String[] args) {
  
  TestHashMap org = new TestHashMap() ;
  
        // add data to personDB
  org.add(new Person("A", "Smith","1234567890","ASmith@atest.com"));
  org.add(new Person("B", "Smith","1234567890", "BSmith@atest.com"));
  org.add(new Person("C", "Walsh","1234567890","CWalsh@atest.com"));
  org.add(new Person("D", "Glatt","1234567890","DGlatt@atest.com"));
  org.add(new Person("E", "Cheong", "1234567890","ACheong@atest.com"));
  org.add(new Person("F", "Walsh","0123456789","FWalsh@sg.com"));
  
        // remove an element from personDB
  org.display("testing ......before remove");  // display all elements in personDB
  org.remove("ACheong@atest.com");
  org.display("after..................");   
      }
  
      public void add(Person p) {
      String key = p.getEmail();
      personDB.put(key, p);
      }
  
      public void remove(String mail) {
  Object obj = personDB.remove(personDB.get(mail));   
  System.out.println(obj + " deleted!");
      }
  }       
  </code></pre>
  
  <p>My output:</p>
  
  <pre><code>testing ......before remove("ECheong@atest.com")
  ID:[ASmith@atest.com]
  ID:[CWalsh@atest.com]
  ID:[FWalsh@sg.com]
  ID:[ECheong@atest.com]
  ID:[DGlatt@atest.com]
  ID:[BSmith@atest.com]
  null deleted!
  after..................
  ID:[ASmith@atest.com]
  ID:[CWalsh@atest.com]
  ID:[FWalsh@sg.com]
  ID:[ECheong@atest.com]
  ID:[DGlatt@atest.com]
  ID:[BSmith@atest.com]
  </code></pre>