return type of Collection.removeIf (original) (raw)

Paul Sandoz paul.sandoz at oracle.com
Mon Apr 29 02:41:40 PDT 2013


On Apr 21, 2013, at 6:06 AM, Akhil Arora <akhil.arora at oracle.com> wrote:

Collection.removeIf is currently specified to return a boolean which is true if any elements were removed. IMHO it would be more useful to have it return an int indicating the number of elements that were removed.

I suppose it saves one from doing:

int sizeBefore = c.size(); if (c.removeIf(...)) { int removed = sizeBefore - c.size();

... }

If one can do:

int removed = c.removeIf(...); if (removed > 0) {

... }

But i think it may be best to stick with the existing semantics of existing bulk operations such as:

boolean removeAll(Collection<?> c);

 * @return <tt>true</tt> if this collection changed as a result of the
 *         call

and stick with the same JavaDoc as above for removeIf.

Paul.



More information about the lambda-dev mailing list