Set<Badge> availableBadges = myService.getAvailableBadges();
List<Badge> allBadges = Arrays.asList(Badge.values());
allBadges.removeAll(availableBadges);
/* Badge is an enumn */
what collections do support remove all ?
The UnsupportedOperationException can be resolved by using a mutable collection, such as ArrayList , which can be modified. An unmodifiable collection or data structure should not be attempted to be modified.
The Java ArrayList removeAll() method removes all the elements from the arraylist that are also present in the specified collection. The syntax of the removeAll() method is: arraylist. removeAll(Collection c);
Arrays.asList
returns a partially unmodifiable implementation (in part of remove*
methods - thanks to @LouisWasserman for the remark) of the List
interface.
EDIT 1: Use an ArrayList
wrapper on it: new ArrayList<Badge>(allBadges);
Your collection might be unmodifiable.
You need to create new List
List<T> list = new ArrayList<>(unmodifiableList);
Now your list is modifiable and you can perform remove and removeAll
operations.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With