I have this method which takes a varargs of Strings, creates a List out of it, and then tries to remove the first element of the list.
public void importFrom(String... files) {
List<String> fileList = Arrays.asList(files);
String first = fileList.remove(0);
// other stuff
}
But as soon as remove gets called, an UnsupportedOperationException is thrown. My guess is that the return List-Type does not support the remove method. Am I correct? What alternatives do I have?
Arrays.asListonly provides a thin wrapper around an array. This wrapper allows you to do most operations on an array using theListAPI. A quote from the JavaDoc:If you really want to remove something, then this might work:
This one creates a real
ArrayList(which supportsremove) and fills it with the contents of another list which happens to be the wrapper around yourString[].