code: public static int[] countSegments(int[] array, int elements,
                                        int segments, int start, int limit) {
  
          int[] counts   = new int[segments];
          long  interval = calcInterval(segments, start, limit);
          int   index    = 0;
          int   element  = 0;
  
          if (interval <= 0) {
              return counts;
          }
  
          for (int i = 0; i < elements; i++) {
              element = array[i];
  
              if (element < start || element >= limit) {
                  continue;
              }
  
              index = (int) ((element - start) / interval);
  
              counts[index]++;
          }
  
          return counts;
      }
docs: Returns an int[] array of length segments containing the distribution
  count of the elements in unsorted int[] array with values between min
  and max (range). Values outside the min-max range are ignored<p>
  
  A usage example is determining the count of people of each age group
  in a large int[] array containing the age of each person. Called with
  (array, 16,0,79), it will return an int[16] with the first element
  the count of people aged 0-4, the second element the count of those
  aged 5-9, and so on. People above the age of 79 are excluded. If the
  range is not a multiple of segments, the last segment will be cover a
  smaller sub-range than the rest.