Forums Register Login

Comparing two Collections for "equality"

+Pie Number of slices to send: Send
I have two Collections A and B. Both contain the same object types.
I want to compare both Collection for equality. This is how I am
doing it now. Pseudocode follows:

Does anybody see any holes in the logic / code above ?
Thanks all
Gavin
+Pie Number of slices to send: Send
You are assuming that all the objects have an equals method defined? (this assumption is ok, I just want to state it.)
You may run into trouble if the collections contain duplicates. For example if collection a is [X,X,Y] and collection b is [X,Y,Y], your code will not catch the difference.
If the collections can't contain duplicates, the second check for containsAll is redundant.
+Pie Number of slices to send: Send
Jeanne,
Thanks for your observations.
The parameters "can" and "may" contain duplicates.
I wonder whether I can just simplify it by doing

Gavin
[ October 01, 2003: Message edited by: Gavin Bong ]
But how did the elephant get like that? What did you do? I think all we can do now is read this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 840 times.
Similar Threads
finder returning collection
Object and String
object comparison
Comparing two byte arrays for equality
compare the collection object
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 18:42:46.