title: HashMap - contains and get methods should not be used together
body: <p>I got the following question from an interview.</p>
  
  <p>I was given a character array like this:</p>
  
  <pre><code>char[] characters = {'u', 'a', 'u', 'i', 'o', 'f', 'u'};
  </code></pre>
  
  <p>I needed to get the distinct characters and counts of each character:</p>
  
  <pre><code>u = 3
  a = 1
  i = 1
  o = 1
  f = 1
  </code></pre>
  
  <p>So I answered in Java with the following code:</p>
  
  <pre><code>HashMap&lt;Character, Integer&gt; map = new HashMap&lt;Character, Integer&gt;();
  int i = 1;
  for (char c : characters) {             
      if (map.containsKey(c)) {
          int val = map.get(c);
          map.put(c, ++val);
      } else map.put(c, i);
  }
  </code></pre>
  
  <p>The interviewer was a solution architect. He asked me why I was using both <code>containsKey()</code> and <code>get()</code> methods here and noted that it was redundant to use both methods. What is his point? What was I doing wrong here? Will my code cause a performance issue, etc.?</p>