Project requirements: convert a comma separated string into a list, and then clone the list and assign it to a new NEWLIST. An error was reported in the title during execution
Text:
Original code
public List<String> test() {
String str = "a,b,c";
List<String> list = Arrays.asList(str.split(","));
//Only ArrayList and LinkedList have clone method, the purpose of clone is to operate on the list afterwards without changing the value of the original list.
ArrayList<String> tempList = (ArrayList<String>)list;
List<String> newList = (List<String>)tempList.clone;
return newList;
}
Correction
//Just replace the code in the replacement line
ArrayList<String> tempList= new ArrayList<>(list);
Similar Posts:
- [leetcode] 140. Word break II word split II
- [Solved] Arrays.asList() Error: java.lang.UnsupportedOperationException
- Convert Object to List>, avoiding Unchecked cast: ‘java.lang.Object’ to ‘java.util.List
- ArrayList reported an error: Unsupported operationexception
- 140. Word Break II
- Wkt to geojson (for multipole)
- [Solved] Exception in thread “main” java.util.ConcurrentModificationException
- Java container — unsupported operation exception
- Raw use of parameterized class ‘Future’
- Perl : Quantifier follows nothing in regex; marked by