title: How to write HashMap to CSV?
body: <p>I have a method <code>countOcc()</code> which prints a list (below).</p>
  
  <pre><code>1:00 ==&gt; 1 hits(s)
  2:00 ==&gt; 4 hits(s)
  3:00 ==&gt; 3 hits(s)
  4:00 ==&gt; 6 hits(s)
  5:00 ==&gt; 14 hits(s)
  6:00 ==&gt; 26 hits(s)
  7:00 ==&gt; 16 hits(s)
  8:00 ==&gt; 25 hits(s)
  9:00 ==&gt; 34 hits(s)
  10:00 ==&gt; 39 hits(s)
  11:00 ==&gt; 33 hits(s)
  12:00 ==&gt; 50 hits(s)
  13:00 ==&gt; 49 hits(s)
  14:00 ==&gt; 51 hits(s)
  15:00 ==&gt; 53 hits(s)
  16:00 ==&gt; 40 hits(s)
  17:00 ==&gt; 20 hits(s)
  18:00 ==&gt; 33 hits(s)
  19:00 ==&gt; 26 hits(s)
  20:00 ==&gt; 18 hits(s)
  21:00 ==&gt; 29 hits(s)
  22:00 ==&gt; 7 hits(s)
  </code></pre>
  
  <p>method:</p>
  
  <pre><code>public void countOcc(ArrayList&lt;Integer&gt; list) {
  
      String aout = new String();
      System.out.println("\n");
  
      Integer[] numbers = list.toArray(new Integer[list.size()]);
  
      Map&lt;Integer, Integer&gt; map = new HashMap&lt;Integer, Integer&gt;();
      for (int i = 0; i &lt; numbers.length; i++) {
          int key = numbers[i];
          if (map.containsKey(key)) {
              int occurrence = map.get(key);
              occurrence++;
              map.put(key, occurrence);
          } else {
              map.put(key, 1);
          }
      }
  
      Iterator iterator = map.keySet().iterator();
      while (iterator.hasNext()) {
          int key = (Integer) iterator.next();
          int occurrence = map.get(key);
  
           System.out.println(key+":00"+ " ==&gt; " + occurrence + " hits(s)");
  
  
      }        
  
  }
  </code></pre>
  
  <p>I'd like to have a csv file on its output:</p>
  
  <pre><code>1:00,2:00,3:00,4:00,5:00,6:00,7:00,8:00,9:00,10:00,11:00,12:00
  1,4,3,6,14,26,16,25,34,39,33,50
  </code></pre>
  
  <p>I know about opencsv but I don't really know how to use it with HashMap.</p>