简体   繁体   中英

How to remove an item from a java List transformed from string[]?

String line = "5 1973 2205 2396 2406";
String[] paperids = line.split(" ");
List<String> paperList = Arrays.asList(paperids);
paperList.remove(0);

This is my Java code, I want to transfer the string[] to List and remove the first item of List, but it doesn't work in the last line, could someone help me ? Thanks a lot.

The List returned from Arrays.asList is not mutable (it can't be changed). This is actually an (annoying) feature of List

Try creating an ArrayList and seeding it with the array values

String line = "5 1973 2205 2396 2406";
String[] paperids = line.split(" ");
List<String> paperList = new ArrayList<String>(Arrays.asList(paperids));
paperList.remove(0);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM