• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Collections.frequency and Collections.disjoint

 
Ranch Hand
Posts: 300
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Marshal
Posts: 79475
379
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
It sure was nice of your sister to lend us her car. Let's show our appreciation by sharing this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic