• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

UnSupportedOperationException

 
Ranch Hand
Posts: 178
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Converting Arrays to Lists:


Changes to the returned list 'write through' to the array



Is the reverse also true?
ie. In List to Array , will the changes to the original list show up in the array.

I tried it in the following code but giving an exception. What is the reasoning behind it?

 
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
See the difference?
Arrays.asList and Collections.toArray

So the Arrays.asList-method is not copying an array into a new list, it gives you just a new List-view on the array. As an array-Object is of fixed size (3 elements in this case) you are not able to add a fourth element into it, neither delete one to get an array of size two. If you are not allowed to do these operations on the array, you are of course not allowed to do the same things to your List-view, as these changes would write through to the array.
Hope, that helps.
 
Ranch Hand
Posts: 447
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

Adding some more to Sasha

We can't call add and remove on that list(Because it is fixed) but we can
call get or set methods.

Thanks
Anil Kumar
[ May 21, 2007: Message edited by: anil kumar ]
 
Meena R. Krishnan
Ranch Hand
Posts: 178
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks to you both!.

I never analyzed the name asList() and toArray(), nice to know.

Also, I never knew that only get and set are allowed with the list returned thro' Arrays.toList. I'm glad I asked.
reply
    Bookmark Topic Watch Topic
  • New Topic