This week's book giveaway is in the Design forum.
We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!
See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

org.apache.collections removeAll

 
Miran Cvenkel
Ranch Hand
Posts: 196
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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 ?
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15214
36
Android IntelliJ IDE Java Scala Spring
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Miran Cvenkel
Ranch Hand
Posts: 196
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic