• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem adding ArrayList to List

 
Tom Henricksen
Author
Ranch Hand
Posts: 144
5
Eclipse IDE jQuery Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This method is throwing an java.lang.UnsupportedOperationException
when I unit test it. It comes from the line with the list.add(inList);


Any suggestions?
Thanks,
Tom
[ September 20, 2005: Message edited by: Tom Henricksen ]
 
Henry Wong
author
Marshal
Pie
Posts: 21493
84
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The Arrays.asList() does not return a fully functional list... Quoted from the Java Docs...

Returns a fixed-size list backed by the specified array.


Since the list that is return is backed by the specified array, it can't change in size. This means add and remove operations do not work.

Henry
 
Layne Lund
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One possible way to fix this is with the following:

This will create a new List that you CAN modify. It also adds all the elements from the List that is created by the asList() method.

HTH

Layne
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic