How to find multiples of the same integer in an arraylist?

Posted by Dan on Stack Overflow See other posts from Stack Overflow or by Dan
Published on 2010-04-29T22:38:09Z Indexed on 2010/04/29 22:47 UTC
Read the original article Hit count: 278

Filed under:
|
|
|

Hi

My problem is as follows. I have an arraylist of integers. The arraylist contains 5 ints e.g[5,5,3,3,9] or perhaps [2,2,2,2,7]. Many of the arraylists have duplicate values and i'm unsure how to count how many of each of the values exist.

The problem is how to find the duplicate values in the arraylist and count how many of that particular duplicate there are. In the first example [5,5,3,3,9] there are 2 5's and 2 3's. The second example of [2,2,2,2,7] would be only 4 2's. The resulting information i wish to find is if there are any duplicates how many of them there are and what specific integer has been duplicated.

I'm not too sure how to do this in java.

Any help would be much appreciated. Thanks.

© Stack Overflow or respective owner

Related posts about java

Related posts about arraylist