Remove Item In ArrayList , Java.lang.UnsupportedOperationException
I want remove item in array list select location My code is List historylist = Arrays.asList(history); if (historylist.size()>=3){ System.out.print
Solution 1:
Change
List<String> historylist = Arrays.asList(history);
to
List<String> historylist = new LinkedList (Arrays.asList(history));
and see this post why this error occur in case of List :
Why do I get an UnsupportedOperationException when trying to remove an element from a List?
Solution 2:
You cannot add or remove elements from the list returned by Arrays.asList
because the list is backed by the original array. To create a list that you can modify, you can do this:
List<String> historylist = new ArrayList<String>(Arrays.asList(history));
Solution 3:
I believe Arrays.asList() creates is fixed-length, and so does not support removing.
Try using an implementation that supports removing like ArrayList instead.
Solution 4:
try this
list.set(position,obj);
Post a Comment for "Remove Item In ArrayList , Java.lang.UnsupportedOperationException"