aspose file tools*
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 Java 8 in Action this week in the Java 8 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: 18135
    
  39

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: 36566
    
  16
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
Collections.unmodifiable* and Immutability
NullpointerException in ArrayList,Vector,LinkedList
IndexOutOfBound Exception in ArraList.isEmpty()
sending a Collection from JSP to Servlet