I get UnsupportedOperationException when deleting from a List in Java

0

I have the following code in Android Java:

List<String> parts = uri.getPathSegments();
parts.remove(parts.size()-1);

I returned that error

  

UnsupportedOperationException

I've searched for internet The error is because it has a fixed size.

Can it be resolved in one way, can the size of a List be altered?

    
asked by Webserveis 07.07.2016 в 18:57
source

2 answers

1

The best way to interact with external lists (ie a list that is the result of an operation) that you want to manipulate is to create a new list from it and then modify it according to your needs. In this case, it would be as simple as doing this:

List<String> parts = new ArrayList<String>(uri.getPathSegments());
//resto de tu código...
    
answered by 08.07.2016 / 21:20
source
0

One solution is to convert it to Array by modifying its size.

List<String> parts = uri.getPathSegments();
parts.toArray(new String[parts.size() -1]);
    
answered by 07.07.2016 в 19:16