Skip to main content

Converting an array to list and then using add()

2 replies [Last post]
waldenboy
Offline
Joined: 2006-07-26
Points: 0

Dear all

when converting a stringArray to a List using asList() it is of fixed length and cannot be added to, how do I get round this so I can add() further to th List.

All the best

Rich.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
regwhitton
Offline
Joined: 2006-09-06
Points: 0

Pass the list returned into the constructor for an ArrayList.

regwhitton
Offline
Joined: 2006-09-06
Points: 0

String[] array = new String[]{"one", "two", "three"};
List list = new ArrayList(Arrays.asList());
list.add("four");