看段简单的代码:
String[] arry={"abc","eee","fff"}; List<String> list= Arrays.asList(arry); list.add("eeef");
Exception in thread "main" java.lang.UnsupportedOperationException at java.util.AbstractList.add(Unknown Source) at java.util.AbstractList.add(Unknown Source) at com.jd.etms.vrs.ws.test.TestList.main(TestList.java:17) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
解决办法:
List<String> list= new ArrayList<String>(Arrays.asList(arry));
List进行remove和add操作时缘何会报UnsupportedOperationException
原文地址:http://blog.csdn.net/wantken/article/details/45914343