Question

i try to compare two lists with each other:

ListA (a1,a2,a3,...)
ListB (b1,b2,b3,...)

I want that a1 is compared to b1, a2 to b2, a3 to b3, ....

But i have to use another method and cannot use .equals!

I have written my own hamcrest matcher. But i have to use a for loop to iterate over the elements. is there a better solution?

for(int i = 0;i<expected.size();i++){
   assertThat(item.get(i),equalsModel(expected.get(0)));
}
Was it helpful?

Solution

How about using iterators instead?

for(
    Iterator<String> it1 = list1.iterator(), it2 = list2.iterator();
    it1.hasNext() && it2.hasNext();
){
    assertThat(it1.next(),equalsModel(it2.next()));
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top