15
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 ?

NimChimpsky
  • 46,453
  • 60
  • 198
  • 311

2 Answers2

36

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);

Andremoniy
  • 34,031
  • 20
  • 135
  • 241
3

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.

double-beep
  • 5,031
  • 17
  • 33
  • 41
T.Thakkar
  • 203
  • 2
  • 9