the solution is to count all elements and then rest it to size() method ... finally you get the duplicates number
K. Tsang wrote:A set contains no duplicates. So the size() method won't help. In fact what does add() returns? boolean right? Now does add return false if you add integer 1 the 2nd time? if so you can have a variable to keep track of this and will return 3 in your code.
i used a List to count the total results and a Set to have no duplicates ... then i got the size() of List minus the size() of Set ... this is probably not the smartest way, but it worked like a charm xD