I am unable to add an element to a list? UnsupportedOperationException

前端 未结 3 1913
粉色の甜心
粉色の甜心 2020-12-17 14:39

This one list object is biting me in the butt..

Any time I try to add an element to it, it produces this:

Caused by: java.lang.UnsupportedOperationEx         


        
3条回答
  •  醉梦人生
    2020-12-17 15:25

    The java docs say asList @SafeVarargs public static List asList(T... a) "Returns a fixed-size list backed by the specified array"

    Your list is fixed size, meaning it cannot grow or shrink and so when you call add, it throws an unsupported operation exception

提交回复
热议问题