File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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 Make it so: Java DB Connections & Transactions this week in the JDBC forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "org.apache.collections removeAll" Watch "org.apache.collections removeAll" New topic

org.apache.collections removeAll

Miran Cvenkel
Ranch Hand

Joined: Nov 23, 2010
Posts: 169

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:
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 15047

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: 169
Hmm, yes, possible. Thanks.

Yeah could post the code, but it become ugly as hell , me spinning around this (-:,%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:
subject: org.apache.collections removeAll
It's not a secret anymore!