• Post Reply Bookmark Topic Watch Topic
  • New Topic

Collections.removeAll()  RSS feed

 
Bartholomew Benson
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I noticed there's a method "public static <T> boolean addAll(java.util.Collection<? super T> c, T... a)" in the Collections class. Why is there no method "public static <T> boolean removeAll(java.util.Collection<? super T> c, T... a)"?
I currently have a class with the following:


(I'm not sure if my reason is OK, but I made a new class to hold a set of Things because I want to later make specialized methods for handling getting/removing/adding Things based upon the Thing's data members)

Why is this? Is there a workaround that wouldn't involve iterating through all elements in things, and removing each one from the set individually?
 
Paweł Baczyński
Bartender
Posts: 2087
44
Firefox Browser IntelliJ IDE Java Linux Spring
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is Set.removeAll(Collection<?> c) method (and also Set.addAll(Collection<? extends E> c))

This is not exactly the same because it takes a Collection instead of vararg but you could use it.
There is Arrays.asList(T... a) method which might come handy.
 
Bartholomew Benson
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you, this seems to work perfectly.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!