aspose file tools*
The moose likes Java in General and the fly likes org.apache.collections removeAll Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "org.apache.collections removeAll" Watch "org.apache.collections removeAll" New topic
Author

org.apache.collections removeAll

Miran Cvenkel
Ranch Hand

Joined: Nov 23, 2010
Posts: 147

a = java.util.List containing [1]
b = java.util.HashSet containing [1,2]

cleared comes out as [1]
I belive it should be []

What is that I dont see ?


Searchable nature photo gallery: http://agrozoo.net/jsp/Galery.jsp?l2=en
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14272
    
  21

Can you show us some more of the code; specifically, how are a and b declared and filled with data?

This gives me a hint: cleared is a Collection<java.util.List>. So a and b are also collections of lists? Which means, a is a List that contains a List that contains an integer 1, and b is a HashSet that contains a List that contains the integers 1 and 2? If that's the case, then your output is not surprising. The removeAll method is going to try to remove the List [1,2] from a, but since a does not contain a List [1,2], it's not going to remove anything.

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
Miran Cvenkel
Ranch Hand

Joined: Nov 23, 2010
Posts: 147
Hmm, yes, possible. Thanks.

Yeah could post the code, but it become ugly as hell , me spinning around this (-:

http://commons.apache.org/collections/apidocs/org/apache/commons/collections/CollectionUtils.html#subtract%28java.util.Collection,%20java.util.Collection%29


removeAll(java.util.Collection collection, java.util.Collection remove)
Removes the elements in remove from collection.


A bit confusing.

Figured that substract does what I want.
But will test that a bit more.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: org.apache.collections removeAll