6680235: (collection) Object count method.
Rémi Forax
forax at univ-mlv.fr
Wed Sep 17 15:30:51 UTC 2008
Leszek Sliwko a écrit :
> Hello,
>
Hello,
>
> I hope I'm on right dev list and I'm posting it as it supposed to be posted.
>
> There is a RFE:
> http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6680235
>
>
>
> "A DESCRIPTION OF THE REQUEST :
> Java Lists currently do not have a way of getting the count of a particular customer within a List.
>
> JUSTIFICATION :
> I ran into this issue when I had a list of objects in which it contained some duplicates, and I needed to know the number of occurrences of specific objects within the list. Basically i built a list of referenced objects from a list of objects and needed the result of how many times a specific referenced customer was in this built list, for later use.
>
>
>
>
> I needed something like... myList.elementCount(obj);
> where elementCount() returns int number of occurrences or -1 if it does not exist in the list, and obj is the assumed element in the list.
>
> I was able to continue by creating a custom iterator, but the above alternative would have been a quicker solution.
>
...
> any inputs/thoughts?
You can't add a method to an interface without breaking the
backward compatibility.
Furthermore java.util.Collections.frequency() already
do a similar job.
This bug should be close as not a defect.
>
> Thanks
>
>
> --
> All of best,
> Leszek
regards,
Rémi
More information about the core-libs-dev
mailing list