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

Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Collections.frequency and Collections.disjoint" Watch "Collections.frequency and Collections.disjoint" New topic

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?

William Brogden
Author and all-around good cowpoke

Joined: Mar 22, 2000
Posts: 12675
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.


Java Resources at
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 36478
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.
I agree. Here's the link:
subject: Collections.frequency and Collections.disjoint
Similar Threads
Generics question
why dont i get an exception here?
LinkedList problem
NullpointerException in Arrays.sort()
unmodifiableList(List list)