aspose file tools*
The moose likes Java in General and the fly likes unmodifiableList(List list) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "unmodifiableList(List list)" Watch "unmodifiableList(List list)" New topic
Author

unmodifiableList(List list)

saikrishna cinux
Ranch Hand

Joined: Apr 16, 2005
Posts: 689
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)


A = HARDWORK B = LUCK/FATE If C=(A+B) then C=SUCCESSFUL IN LIFE else C=FAILURE IN LIFE
SCJP 1.4
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10210
    
166

Whats the exception that you are getting. The following program works using LinkedList:



[My Blog] [JavaRanch Journal]
Edwin Dalorzo
Ranch Hand

Joined: Dec 31, 2004
Posts: 961
I run your code and there are no errors in it.

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

Tony Morris
Ranch Hand

Joined: Sep 24, 2003
Posts: 1608
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).


Tony Morris
Java Q&A (FAQ, Trivia)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: unmodifiableList(List list)