title: Why is the "else" code block executed for this for loop?
body: <p>I think I understand the first statement. It's saying, if the items in "words" are NOT in "frequencies", then add them and assign a value of 1 to each, right? 
  What I am more confused about is why the "else" block gets executed and how it works. I understand the output, but not quite how it works. It obviously recognizes that a particular word appears more than once but how does it recognize that? And again, why does it go to the "else" block if the first statement is true? </p>
  
  <pre><code>public class Testing {
  
    static List&lt;String&gt; list() {
  
      List&lt;String&gt; words = new ArrayList&lt;String&gt;();
  
      words.add("Cherry");
      words.add("Banana");
      words.add("Apple");
      words.add("Banana");
      words.add("Berry");
  
      return words;
    }
  
    static Map&lt;String, Integer&gt; ArrayFrequencies(List&lt;String&gt; words) {
  
      Map&lt;String, Integer&gt; frequencies = new HashMap&lt;String, Integer&gt;();
  
      for (String elements : words) {
  
        if (!frequencies.containsKey(elements)) {
          frequencies.put(elements, 1);
        } else {
          frequencies.put(elements, frequencies.get(elements) + 1);
        }
      }
  
      return frequencies;
    }
  
    public static void main(String[] args) {
  
      System.out.println(ArrayFrequencies(list()));
    }
  }
  </code></pre>
  
  <p>output : {Apple=1, Cherry=1, Berry=1, Banana=2}</p>