• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Conversion of Array into List

 
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For the code provided below,



why do we get the Runtime Exception.

while all the methods of List Interface are accessible by the List(converted
from Array), why is it not possible to add any new elements into the new Converted List.

Please Explain....
 
Ranch Hand
Posts: 177
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you goto the API, ou would find this:
Returns a fixed-size list backed by the specified array. (Changes to the returned list "write through" to the array.)
So this means that the list is fixed-size and hence you cannot add to it.
However the list is synchronized with the array, this means that if you change any element in the array, same would be reflected in the list.
You can do this by:
 
Pradeep Balasubramanian
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Now I am clear

Also,
Once the length of array is specified , its size cannot be changed later.

Thank you, for pointing the error made by me.

[ September 16, 2008: Message edited by: Pradeep Balasubramanian ]
 
Paul Somnath
Ranch Hand
Posts: 177
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That is so obvious.
When you say:


You define the size of the array at compile time and cannot change it at runtime. Thats is what lists are for.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic