aspose file tools*
The moose likes Java in General and the fly likes Collections.frequency and Collections.disjoint Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Collections.frequency and Collections.disjoint" Watch "Collections.frequency and Collections.disjoint" New topic
Author

Collections.frequency and Collections.disjoint

Patricia Samuel
Ranch Hand

Joined: Sep 12, 2007
Posts: 300
Hi All,

Following is the code snippet for collections's two method - frequency and disjoint.

When i used it in the following manner, it returned me "UnsupportedOperationException"



Why is it?

Thanks
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12788
    
    5
According to the API JavaDocs, java.util.Collections methods may throw UnsupportedOperationException if the underlying collection you are operating on does not support certain operations.

See the discussion of the disjoint() method in the Javadocs for more.

Bill
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38872
    
  23
If you go to the List or Set or Collection interfaces, you find some methods labelled "optional." Begging the question of whether you should have optional methods in interfaces in the first place, if you invoke those methods they don't do anything; obviously they have the short and sweet implementation below.You will have to find implementations which implement every method. Read the Collections#nCopies documentation and see what it returns. Then work out how you are supposed to use that List's add method. And reading the Collection#add(E) method's details will help too.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Collections.frequency and Collections.disjoint