title: Split the numbers in a different range
body: <p>I am trying to measure how much time each thread takes in inserting to database. I have captured all those performance numbers in a <code>ConcurrentHashMap</code> named map like how much time each thread is taking in inserting. In that concurrent hash map it will be something like this.</p>
  
  <pre><code>Key- 10
  Value- 2
  </code></pre>
  
  <p>So that means, 2 Calls came back in 10 ms. Another example below</p>
  
  <pre><code>Key - 20
  Value -1
  </code></pre>
  
  <p>which means, 1 Call came back in 20 ms.</p>
  
  <p>And that map will contain lot more data means lot more key value pair.</p>
  
  <p>So now I am trying to do something like below by using the same map above, that means I need to iterate the above map to get the below numbers in that particular range. Is that possible to do?</p>
  
  <pre><code>How many calls(X number) came back in between 1 and 20 ms
  How many calls(X number) came back in between 20 and 40 ms
  How many calls(X number) came back in between 40 and 60 ms
  How many calls(X number) came back in between 60 and 80 ms
  How many calls(X number) came back in between 80 and 100 ms
  How many calls(X number) came back after 100 ms
  </code></pre>
  
  <p>Some code that I thought of initially.</p>
  
  <pre><code>SortedSet&lt;Long&gt; keys = new TreeSet&lt;Long&gt;(map.keySet());
  for (Long key : keys) {
      System.out.print(key + " : ");
      for (int i = 0; i &lt; map.get(key); i++) {
                   // Not sure what I am supposed to do here?
      }
      System.out.println();
  }
  </code></pre>
  
  <p>Can anyone help me here? </p>
  
  <p><strong>Update:-</strong></p>
  
  <p>My map sample value-</p>
  
  <pre><code>{31=3, 48=1, 33=1, 30=12, 43=1, 38=1, 32=1}
  </code></pre>
  
  <p>It means total call was <code>3+1+1+12+1+1+1 = 20</code> by adding <code>value</code> from the <code>map</code></p>
  
  <p>And out of that I need to figure out the above scenario means something like this</p>
  
  <pre><code>How many calls(X number) came back in between 1 and 20 ms
  How many calls(X number) came back in between 20 and 40 ms
  How many calls(X number) came back in between 40 and 60 ms
  How many calls(X number) came back in between 60 and 80 ms
  How many calls(X number) came back in between 80 and 100 ms
  How many calls(X number) came back after 100 ms
  </code></pre>
  
  <p>Below is my code that I have tried with the below suggestion-</p>
  
  <p>private static void drawHistogram(Map map) {</p>
  
  <pre><code>int counter[] = new int[6];
  
  for (Integer key : map.keySet()) {
      System.out.println("" + key);    
  
      // add sample
      int idx = key / 20;
      idx = Math.min(idx, counter.length - 1);
      counter[idx]++;
      }
  
  for (int i = 0; i &lt; counter.length; i++) {
      System.out.println(counter[i] + " came back in between " + i * 20 + " and " + (i + 1) * 20
              + " ms");
  }
  </code></pre>
  
  <p>}</p>
  
  <p>As you can see, I have 20 calls made but this is showing only 7 calls. Anything wrong I did? This is the output I got-</p>
  
  <pre><code>0 came back in between 0 and 20 ms
  5 came back in between 20 and 40 ms
  2 came back in between 40 and 60 ms
  0 came back in between 60 and 80 ms
  0 came back in between 80 and 100 ms
  0 came back in between 100 and 120 ms
  </code></pre>
  
  <p>which shows only 7 calls. But there are 20 calls.</p>