开发者

list.add("stuff"); crashes

I'm trying to make a simple list.

I've got this:

    String valuesArray[] = {"473", "592", "1774", "341", "355", "473", "950", "500", "44", "946.35", "750", "950"};
    List<String> valueList = Arrays.asList(valuesArray); 

Whenever I try to add something to the list, it force closes.

    valueList.add("Test");

And it really seems to only happen when I try to add to the 开发者_运维百科list. I'm able to get values from the list, just not add to it.


As you can see from the docs for Arrays.asList(), the List returned from that method is fixed size. If you want something more versatile, you might try:

List<String> valueList = new ArrayList<String>(Arrays.asList(valuesArray));


Arrays.asList() returns a fixed size list. You cannot add to it.


Another option is to loop through the array and add them in one at a time, then, it won't be a fixed size for the list and you can do all the list operations that you want.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜