dekros
dekros

Reputation: 59

ArrayList<String>.add throws UnsupportedOperationException

I wrote this code:

List<String> doneTiers = new ArrayList<>();
if (ps.getData("achievements.Done") != null) {
    doneTiers = Arrays.asList(ps.getData("achievements.Done").split("/./"));
}
Msg.debug(tier, tier.getName());
doneTiers.add(tier.getName());// dodany
ps.setData("achievements.Done", DataUTIL.format(doneTiers, "/./"));

and I have error in this line doneTiers.add(tier.GetName());

UnsupportedOperationException

Upvotes: 0

Views: 265

Answers (1)

Adam Michalik
Adam Michalik

Reputation: 9945

Arrays.asList() creates a fixed-size list, so once created, you cannot add more elements to it. Since you already initialized doneTiers with new ArrayList<>(), you can use addAll like this:

doneTiers.addAll(Arrays.asList(ps.getData("achievements.Done").split("/./")))

Upvotes: 3

Related Questions