= { "qweqweqwe", "asdasdasd" }; // line 1
List<String> list = Arrays.asList(array); // line 2
list.add("ASDASD"); // UnsupportedOperationException
Why UnsupportedOperationException is thrown from AbstractList class if asList at line 2 returns ArrayList?
List implementation obtained by asList (AbstractList) does not support element adding. asList returns immutable collection, not an array list. To modify collection created with asList method you need to wrap it in another list, for instance, ArrayList: List list = new ArrayList(Arrays.asList(a, b, c))
Обсуждают сегодня