This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes UnsuppourtedOperationException when tried to modify the Collections.unmodifiable format . Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "UnsuppourtedOperationException when tried to modify the Collections.unmodifiable format ." Watch "UnsuppourtedOperationException when tried to modify the Collections.unmodifiable format ." New topic
Author

UnsuppourtedOperationException when tried to modify the Collections.unmodifiable format .

PavanPL KalyanK
Ranch Hand

Joined: Feb 28, 2009
Posts: 212


I read that we would get an UnsuppourtedOperationException when tried to modify the Collections.unmodifiable format .

But why i am not getting any exception .The console is blank
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18507
    
  40

But why i am not getting any exception .The console is blank


The Collections.unmodifiableList() method returns a read-only list. It doesn't change the list that is passed to it.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
PavanPL KalyanK
Ranch Hand

Joined: Feb 28, 2009
Posts: 212
I tried as you said .and i got my Exception

Exception in thread "main" java.lang.UnsupportedOperationException
at java.util.Collections$UnmodifiableCollection.add(Unknown Source)
at Tes.main(Tes.java:19)


Thank you.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 37926
    
  22
You need to read the documentation for List#add() which explains it. Also the Collections#unmodifiableList(java.util.List) method.

The return value is specifically designed not to allow additions or removals from the List. So it throws Exceptions if you try to use the unimplemented methods.
If the original List changes, the "unmodifiable" copy changes to match, however.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: UnsuppourtedOperationException when tried to modify the Collections.unmodifiable format .
 
Similar Threads
collection classes
NullpointerException in ArrayList,Vector,LinkedList
sending a Collection from JSP to Servlet
IndexOutOfBound Exception in ArraList.isEmpty()
Collections.unmodifiable* and Immutability