Ok bit of a basic question here but I wanted to know what the best way to go about this…
I have a HashSet that I am adding objects to, the .add() method will only add an object if it is not already present. But what I want to do is add ALL objects, then at the end get the following results..
-Number of unique (distinct) objects
-The average frequency of objects
Could someone point me in the right direction?
Thanks in advance
HashSet isn’t really suited for keeping track of individual counts but HashMap is nearly perfect.
When run, this standalone snippet outputs