• 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 wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

unmodifiableList(List list)

 
Ranch Hand
Posts: 689
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i am using Linkedlist in my program and i want to make it unmodifiable thru out my program so i am using this method


LinkedList<Object> l=new LinkedList<Objectl.add("a");
l.add("b");
l.add("c");
l.add("d");
List list=Collections.unmodifiableList(l);//here is an error

while i use arraylist,vector in place of linkedlist it is not showing any error

why?
linkedlist is also implementing the List interface as arraylist and vector does


:roll:


please somebody give me the best suggestion with example( iam learning OOPs through collection frame work)
 
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Whats the exception that you are getting. The following program works using LinkedList:

 
Ranch Hand
Posts: 961
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I run your code and there are no errors in it.

What errors do you receive? Compile time? Run time?

 
Ranch Hand
Posts: 1608
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You are likely receiving a compile-time warning.
List list=Collections.unmodifiableList(l);//here is an error
Try this:
List<Object> list=Collections.unmodifiableList(l);//here is an error

As a side note, I strongly recommend against using collections in this way (or even at all).
 
reply
    Bookmark Topic Watch Topic
  • New Topic