ajwest
ajwest

Reputation: 258

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.

Upvotes: 2

Views: 1108

Answers (3)

James Black
James Black

Reputation: 41858

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.

Upvotes: 0

rid
rid

Reputation: 63442

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

Upvotes: 1

kabuko
kabuko

Reputation: 36302

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));

Upvotes: 8

Related Questions