title: Building a frequency count map in groovy.
body: <p>I have an array and i want to build a map out of it recording the frequency of elements in the array. So for the example below the map = [15:2, 16:1] is what it will look like. How do I do this in Groovy ?</p>
  
  <pre><code>static void doSomething()
      {
          def a = [15,16,15]
          def map = []
          a.each{
              k,v-&gt; 
              if(map.contains(it)) 
              map.putAt k, v++
              else
              map.putAt k, 1;
          }
  
          println map
      }
  </code></pre>