How do i test for the equality of two iterators using JUnit?
Is there any built in method or is it just by comparing each and every element in that?
Thanks, Sriram
You can't (and needn't) test the equality of iterators, only that of the underlying collections. To do that, you can iterate through both and compare each pair of elements in turn, as you guessed. Note that this effectively consumes at least one of the iterators. And the result is dependent on the state of the iterators at the start of the test, so this method is brittle. Therefore it is best to get hold of the underlying collections and test them directly for equality (using their equals method), whenever you can.
Why would you ever want to test the equality of two iterators? If you explain your concrete problem, we may be able to offer a better alternative.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With