• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

Generating distribution from an ArrayList

 
Greenhorn
Posts: 16
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

I have a sorted ArrayList of values. I would like to get the distribution of the values. For example:

- Say I have 500 values, ranging from 1-100.
- I want to break them up into groups, say 10 groups: values 1-10, 11-20, 21-30, etc...
- I want the counts of each of the 500 values that fall into each category. For example, 5 of the 500 are valued at 1-10, 20 between 11-20, etc...
- However, I do not know the ranges of values in my ArrayList, it could be ranging from 1-30 or 1-200, but I want to break it up into, for example, 10 groups.

Does anyone know how to do this?
 
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As your ArrayList is sorted the range is from the value of the first entry to the value of the last entry.

You can use some simple maths to work out what values should go into each of your ten groups.

To count the number of values in the first group you iterate thru the ArrayList until you reach a value that is outside the range.
To count the number of values in the second group you iterate thru the ArrayList starting at the previous end point until you reach a value that is outside the range.
Repeat for each of the groups.
 
Legend has it that if you rub the right tiny ad, a genie comes out.
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic