• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Collections.frequency and Collections.disjoint

 
Patricia Samuel
Ranch Hand
Posts: 300
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13074
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 50278
80
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic