Win a copy of Pro Spring MVC with WebFlux: Web Development in Spring Framework 5 and Spring Boot 2 this week in the Spring forum!
  • 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
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Rob Spoor
  • Bear Bibeault
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:
  • Frits Walraven
  • Himai Minh

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: 72950
330
  • 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.
 
A berm makes a great wind break. And we all like to break wind once in a while. Like this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic