Alok Pandey

Alok Pandey

  • NA
  • 9.4k
  • 6.7m

How to count total number of occurrence

Jan 12 2012 11:07 PM
Hi,

I am using arraylist, in which I have added some number. I want to count total number of occurrences of number? Like,

ArrayList ar=new Arraylist();

ar.Add(2);ar.Add(3);ar.Add(3);ar.Add(2);ar.Add(2);ar.Add(7);ar.Add(2);ar.Add(2);

Output should be like this. 2 - 5 times
                                    3 - 2 times
                                    7 - 1 times

Is there any method which can solve this problem without writing full code or I have to take all numbers and check with all remaining numbers? Please help me.

Thanks in advance.

Answers (2)