java.lang.UnsupportedOperationException at java.util.AbstractList.remove(Unknown Source)

前端 未结 5 1923
北荒
北荒 2021-02-02 06:03

I have tried below code

String s[]={\"1\",\"2\",\"3\",\"4\"};  
Collection c=Arrays.asList(s);  
System.out.println(c.remove(\"1\") +\"  remove flag\");  

Syste         


        
5条回答
  •  时光取名叫无心
    2021-02-02 06:23

    Easy work around is just to pass in the List into an ArrayList's constructor.

    For example:

    String valuesInArray[]={"1","2","3","4"};  
    List modifiableList = new ArrayList(Arrays.asList(valuesInArray));
    System.out.println(modifiableList.remove("1") + "  remove flag");  
    System.out.println(" collcetion "+ modifiableList); 
    

    Response:

    true remove flag

    collcetion [2, 3, 4]

提交回复
热议问题